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

Conditionally flag some columns based on group of data

Hi,

I have a dataset that looks like this:

 

Product IDDealerModelDealerModelKeyCreationMonthExpected First FlagMainMonthExpected Final Flag
abc123Y121226Y12122620190402019041
abc124Y121226Y12122620190402019021
abc125Y121226Y12122620190302019121
abc126Y121226Y12122620190402017010 (because 201701 is older than 201902)
abc127Y121226Y1212262019021(because creation month is oldest)2019121
abc128A100123A10012320191202018070
abc129A100123A10012320190402018080
abc130A100123A10012320180912018080
abc131A100900A10090020190402019031
abc132A100900A10090020180712019041
abc133A100900A10090020191202019021


Problem Statement: For each dealer and model combination(DealerModelKey),
I want to create 2 flag columns in Dax:

Expected First Flag: For a group of DealerModelKey, find the oldest CreationMonth. Call it 1 and all others as 0.
E.g. Since Y121226 has 201902 as the oldest date it is made to 1 and all others as 0.

 

Expected Final Flag: Compare Expected first flag and MainMonth column. All months older than Expected first flag i.e when Expected first flag = 1, then all months older than that month should be made 0 else 1.

 

Thanks

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You can create two columns like DAX below.

 

Expected First Flag1 = var d=CALCULATE(MIN('Table'[CreationMonth]),ALLEXCEPT('Table','Table'[DealerModelKey]))
return IF('Table'[CreationMonth]=d,1,0)
 
Expected First Flag2 = var d=CALCULATE(MIN('Table'[CreationMonth]),ALLEXCEPT('Table','Table'[DealerModelKey]))
return IF('Table'[MainMonth]>=d,1,0)

Result:

 

60.png

 

 

 

 

 

 

 

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You can create two columns like DAX below.

 

Expected First Flag1 = var d=CALCULATE(MIN('Table'[CreationMonth]),ALLEXCEPT('Table','Table'[DealerModelKey]))
return IF('Table'[CreationMonth]=d,1,0)
 
Expected First Flag2 = var d=CALCULATE(MIN('Table'[CreationMonth]),ALLEXCEPT('Table','Table'[DealerModelKey]))
return IF('Table'[MainMonth]>=d,1,0)

Result:

 

60.png

 

 

 

 

 

 

 

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Amy,

 

Thanks for the reply. Could you also please explain how the calculation works

Also, my if statement is not accepting non-measure value i.e CreationMonth

It is a whole number in my dataset.

Hi @Anonymous ,

 

The formulas above are created using calculated column instead of measure.

 

Best Regards,

Amy

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.