Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Measure, nested-IF, text

Hello to all DAX gurus,

source_table:

Location (text)Phase (text)

Id (number)

Value (number)
AP1110
BP1210
BP2310
CP2410
CP35

10

Logic:

For each location:

if Phase- P1, calculated (Value; FILTER (Source_table; Phase - P1));

if Phase- P2, is calculated (Value; FILTER (Source_table; Phase - P2));

if Phase- P3, calculated (Value; FILTER (Source_table; Phase - P3));

Explanation:

For each location, if there is a P1 value, return the value P1.

If there is no P1 value, use the value P2.

If there is no P2 value, use the P3 value.

How can I achieve a result table like the following, with the above logic, using only the measure? I use the SAAS model, so I can only create a new measure (no calculated columns).

Result_table:

LocationPhaseIdnew_measure
AP1110
BP1210
CP2410

I tried to use RANKX, KEEPFILTER, ISFILTERED, but so har has not succeeded.

Thank you in advance 🙂

1 ACCEPTED SOLUTION

@Anonymous try this

 

Measure = 
VAR __p1 = CALCULATE ( [Value Measure], Table[Phase] = "P1" )
VAR __p2 = CALCULATE ( [Value Measure], Table[Phase] = "P3" )
VAR __p3 = CALCULATE ( [Value Measure], Table[Phase] = "P3" )
RETURN
SWITCH ( TRUE(),
 __p1 <> BLANK(), __p1,
 __p2 <> BLANK(), __p2,
 __p3
)

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

If your fact table have same order as sample, you could try the following DAX:

Measure  =
IF (
    SELECTEDVALUE ( 'Table'[Id] )
        = CALCULATE ( MIN ( 'Table'[Id] ), ALLEXCEPT ( 'Table', 'Table'[Location] ) ),
    [Your value]
)

Here is the result.

2-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

@v-eachen-msft  thanks for the help, but the ID is random unfortunately, so I can't use MIN. I'm still trying to understand why I get all the Phase on the result table.

parry2k
Super User
Super User

@Anonymous really not sure what does this means:

 

For each Location:

if Phase= P1, get Value;

else if Phase= P2, get Value;

else if Phase= P3, get Value

 

all are getting value?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k I added explanation to the problem above. Sorry if it wasn't clear.

@Anonymous try this

 

Measure = 
VAR __p1 = CALCULATE ( [Value Measure], Table[Phase] = "P1" )
VAR __p2 = CALCULATE ( [Value Measure], Table[Phase] = "P3" )
VAR __p3 = CALCULATE ( [Value Measure], Table[Phase] = "P3" )
RETURN
SWITCH ( TRUE(),
 __p1 <> BLANK(), __p1,
 __p2 <> BLANK(), __p2,
 __p3
)

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k the result_table is correct if it only has Location, ID, and new_measure columns, but when I added the Phase column, it got messed up and showed duplicated Location, new_measure value for all the Phase P1-P3. How can I avoid this? Thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors