cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BeSe
Helper I
Helper I

Get column name when it is equal value X

Hello, glad I have found this forum. I am pretty much a newbie to PowerAutomate but I think it is a great tool.

I use Get-items with ODATA filter to get a specific line from a SharePoint list. This step is successful.

My problem: From this line I want to get the column name if the value is a certain string, let's say "pick me". So "pick me" is always the same string but in different lines it is in different columns. I don't know which action I shall use as it seems to me you always have to use a fixed known column for a condition matching a specific value or not. But as said, the column is not fixed, only the value.

Hope it is understandable.

BR

 

23 REPLIES 23
v-yueyun-msft
Community Support
Community Support

Hi , @BeSe 

According to your description, you want to get the columnNames which contains the "pick me " value .

This is my test SharePoint List:

vyueyunmsft_0-1701828103255.png

This is my flow result :

vyueyunmsft_1-1701828119966.png

This is my flow:

vyueyunmsft_2-1701828132045.png

(1)The "Get items","Select","Initial variable" action:

vyueyunmsft_3-1701828199637.png

(2)The "Apply to each" action :

vyueyunmsft_4-1701828351997.png

replace(replace(string(items('Apply_to_each')),'{',''),'}','')
split(outputs('Compose'),',')
replace(split(item(),':')[0] , '"','')
items('Apply_to_each')?[items('Apply_to_each_2')]
 
 
(3)The last action:
vyueyunmsft_5-1701828395957.png
union(variables('ColumnNames'),variables('ColumnNames'))
 

Best Regards,

Yueyun Zhang

Hi @v-yueyun-msft ,

thanks for the fast and detailed reply!

First of all an information or potential trap: I have tried to create your steps in the new designer and it gave me syntax errors right in the very first compose-action. I continued in the old designer and it was accepted right away.

Anyway, the flow looks amazing but does not give me the desired result. Keypoint is the "Select 2"-action. Input gives this:

[
"\"col1\":[\"@odata.type\":\"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference\"",
"\"Id\":0",
"\"Value\":\"random\"]",
"\"col2\":[]",
"\"col3\":[\"@odata.type\":\"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference\"",
"\"Id\":1",
"\"Value\":\"pick me\"]",
"\"col4\":[]",
"\"col5\":[]",


]

 

Output cuts to much so the value "pick me" is removed and can not match the condition in the next step:

[
"col1",
"Id",
"Value",
"col2",
"col3",
"Id",
"Value",
"col4",
"col5",
]

BR

 

Hi , @BeSe 

 

 

Thanks for your quick response! This is my Compose action output in my Apply to each loop:

vyueyunmsft_0-1701916498420.jpeg

 

And this is my Select2 action Input:

vyueyunmsft_1-1701916498422.jpeg

 

Can you show me what is your output to loop in your Apply to each in your run history? [Like the Select action output]

And i am not surely understand your "Output cuts to much so the value "pick me" is removed and can not match the condition in the next step".Can you give me some sample data and your end result you need in your side ?


Best Regards,

Yueyun Zhang

 

Hi @v-yueyun-msft ,

this is my Select action output (so the first one which is not in a loop according to your flow):

[
{
"col1": [
{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
"Id": 0,
"Value": "random"
}
],
"col2": [],
"col3": [
{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
"Id": 1,
"Value": "pick me"
}
],
"col4": [],
"col5": []
}
}
]

The Input and Output of the Select 2 (which is in the loop) I gave you in my previous post. That is what I meant - the output cuts the values (e.g. the important one "pick me").

 

So my end result according to my example should be "col3" cause in that column there is the value "pick me".

One question: What is your compose-action there for? If I understand correctly it should remove { and } but I don't see it in my input anyway. And in yours of your last screenshot I don't see any as well?

I really appreciate your help. Thanks a lot.

BR

 

 

What about this?

Constrains:

  • Finds only the first "pick me" in a row.
  • If your col names contain special characters (like space) you have to decode them.

Chriddle_0-1701937531958.png

Map Id:

 

item()['Id']

 

Map ColName:

 

xpath(
	xml(json(concat('{"Root":', item(), '}'))),
	'name(//*[.="pick me"])'
)

 

 

Output:

 

[
  {
    "Id": 0,
    "ColName": "Col0"
  },
  {
    "Id": 1,
    "ColName": "Col1"
  },
  {
    "Id": 2,
    "ColName": "Col2"
  },
  {
    "Id": 3,
    "ColName": ""
  }
]

 

 

Hi , @BeSe 

Thanks for your quick response! Yes, you need to convert your input to this :

vyueyunmsft_0-1701939364769.png

If you have this input :

vyueyunmsft_1-1701939385531.png

You can use the select to extract the value you need :

vyueyunmsft_2-1701939458541.png

 For explanation, apply to each this array , one of it is like this:

vyueyunmsft_3-1701939494637.png

So we can replace the { and } to  '' , will replace to this:

vyueyunmsft_4-1701939515323.png

Then we can split by the ','  , and usethe select action to extract the COlumnNames as an array:
["col1","col2","col3","col4","col5"]

 

Then we can apply to this COlumnNames Array to judge if contains the special value.

 

Best Regards,

Yueyun Zhang

Hi , @BeSe 

I also test it in my side , it works good from your example data :

[
  {
    "col1": [
      {
        "odatatype": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
        "Id": 0,
        "Value": "random"
      }
    ],
    "col2": [],
    "col3": [
      {
        "odatatype": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
        "Id": 1,
        "Value": "pick me"
      }
    ],
    "col4": [],
    "col5": []
  },
  {
    "col1": [
      {
        "odatatype": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
        "Id": 0,
        "Value": "random"
      }
    ],
    "col2": [],
    "col3": [],
    "col4": [
      {
        "odatatype": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
        "Id": 1,
        "Value": "pick me"
      }
    ],
    "col5": []
  }
]

Best JSON Formatter and JSON Validator: Online JSON Formatter

 

vyueyunmsft_5-1701940014527.png

This code is the same my first reply above.

 

And the result is as follows:

vyueyunmsft_6-1701940057520.png

 

Best Regards,

Yueyun Zhang

 

 

 

Hello @Chriddle ,

thanks for your reply. I get an error when trying out claiming property 'Id' does not exist and available properties are only col1,col2...(please be aware my actual column names are not incremented col[n] but different strings.) I think it is because your array is built differently compared to mine and I am afraid I don't know how to adapt your solution to mine.

BR

Hi @v-yueyun-msft ,

for me it almost works. I get an error for the columns that got no actual data in it like:

"col2": [],

So I am surprised it works in your case with my sample? Anyway seems like only a small step and I will try to solve this tomorrow. Just wanted to give a current status.

BR

In my suggestion, the actual column names don't matter, except for Id.

I assumed that you also need to identify the row in which "pick me" occurs.

So you need to change "Id" to your row id column name (or remove this map from the selection if it's not needed).

Hi , @BeSe 

Thanks for your quick response!

For your length=0 array , you need to extract the json add the '?' to avoid the error.

vyueyunmsft_0-1702001942875.png

 

 

 

 

If I misunderstand what you mean, you can describe your needs and your expected outcomes in detail so that we can better help you.


Best Regards,

Yueyun Zhang

 

 

The actual column name is my desired result.

How shall I change "Id" to my column name when I do not know which name I need in that state? Sorry, don't get it. If I leave mapping of Id it gives me this:

[
  {
    "ColName": ""
  }
]

Hi @v-yueyun-msft ,

I have already created it exactly to your screenshot, including the '?' you have marked in your screenshot. So including ?[0]? covers if the array=0 or how could one explain it? If so, the array does not equal 0 it is [] e.g. example "col2":

BeSe_0-1702029642265.png

So if I only map columns with actual values in it, it works. But I do need to cover the case the column shows me '[]'.

This is the failure I get with my actual named columns:

BeSe_1-1702030283064.png

BR

Hi , @BeSe 

First,sorry for my delay response due to weekend.

Thanks for your quick response! According to your error code :

vyueyunmsft_0-1702264878420.jpeg

 

This means your [DKR] is not an array , it is an Object . So what is your actually [DKR] in your Json? 

And for your example ,it has only col1,col2,col3,col4,col5.... I have not found your [DKR].

If  possible , can you give me your sample json and your end result to me so that i can fully understand your need!


Best Regards,

Yueyun Zhang

Hi @v-yueyun-msft ,

sorry for the confusion. Maybe I have not pointed out too clearly - last screenshot was my prod data, before this I used example terms for my problem. But the variable definitions are the same, so it makes no difference. However, I screenshoted my real data and put some comments on it, hopefully this makes it clear:

BeSe_0-1702280283857.png

Please be aware of that in my posted failure message every column is mentioned:

BeSe_1-1702280504353.png

"Select_only_column_names_and_according_values" is the select-action you posted on thursday.

So to my understanding the problem is not DKR, but the columns that have no data (-> e.g. "CHZ": []...) in it....because if I only map columns with data it works.

BR

Hi , @BeSe 

Thanks for your quick response! For your screenshot , we can see that :

vyueyunmsft_0-1702281606051.png

So in the Select Action , if you need to extract the [CKR] and [TKU] field, you need to use this code :
item()?['CKR']?['Value']

item()?['TKU']?['Value']

 

 

You can not use the item()?['CKR']?[0]?['Value'] due to it is not an array in json.

 

Best Regards,

Yueyun Zhang

Hi @v-yueyun-msft ,

thank you for you fast reply!

Ok, got this. But I need a function that can handle both cause as said initially the values change. Cause this output equals one week which is one row. Next week, so in the next row the values will be different - then CHZ is not empty anymore but e.g. DKR and TKU are. Do I need to convert every column first in either an object or an array? I guess this has something to do with SharePoint's list defaults to set empty columns as an array and not an object?

Cause I did not manipulate anything, I followed your advisories you offered. BR

HI , @BeSe 

Do you mean you want to handle the blank array or blank object? As the expression in PowerAutomate ,like :
item()?['CKR']?['Value']

 

If your CKR column has no object , it will return null without the error code in my understand due to the ? in the Expression.

 

 

 

If I misunderstand what you mean, you can give me some sample data and your expected outcomes in detail so that we can better help you.


Best Regards,

Yueyun Zhang

 

 

Hey @v-yueyun-msft ,

I changed it to your suggestion and now I got this error:

BeSe_1-1702284126194.png

BR

 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (963)