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
anil_power
Regular Visitor

last 3 Days Variance per ID

Hi all,

         I have a dataset of ID, Date, and value. I am trying to calculate the last 3 values of ID based on the last 3 dates. So once we get the last 3 values based on these trying to write a condition. If all three values of an ID is the same eg red then "Red". If any of the value is red other than green then "Yellow" and anyone value is green then "Green".

 

This is the sample dataset I am working on:

 

 Data.JPG

These are the expected results:

exp1.JPG 

The actual expected result.

Exp2.JPG   

 

Sample pbix : https://www.dropbox.com/s/7p5a9ba0g9znac6/Sample.pbix?dl=0

 

Please someone help me with a solution

 

Thank You

7 REPLIES 7
Greg_Deckler
Super User
Super User

Can you post your source example data as text? That's a lot to type manually.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I can't really fathom your logic as to how you are getting red, yellow, green, I'm not comprehending your explanation of it. But it is going to be something like:

 

Last 3 = 
VAR __tmpTable = SUMMARIZE(FILTER(ALL('Sample'),[ID]=EARLIER([ID]) && [Date]<=EARLIER([Date]) && [Date]>=EARLIER([Date])-2),'Sample'[Bucket])
VAR __rows = COUNTROWS(__tmpTable)
RETURN
IF(__rows = 1,MAXX(__tmpTable,[Bucket]),IF("Yellow" IN __tmpTable, "Yellow", IF("Green" IN __tmpTable, "Green", "Red")))

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Greg,

         Can you please attach pbix file so it would be helpful. 

Sure.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks Greg, your reply was really helpful.

 

The Bucket column in data I am calculated using below formula. 

 

Bucket = Switch ( True(),

And( [Avg Discount %]>=-10 ,[Avg Discount %] < [TMax 5% Var]) , "Green",
And( [Avg Discount %]>=[TMax 5% Var],[Avg Discount %] < [TMax 15% Var]) , "Yellow",
And( [Avg Discount %] >= [TMax 15% Var],[Avg Discount %] < 500), "Red"

)

 

and I have used the calculated column formula given by you, but I am facing dependency error while applying the formula

 Test1.JPG

 

Hi @anil_power,

 

Please refer to this blog to avoid A circular Dependency was detected" error.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Greg,

 

           Thanks for the reply. Below are the sample files.

Sample excel file: https://www.dropbox.com/s/umb808dhuay7jjw/Sample.xlsx?dl=0

Sample pbix : https://www.dropbox.com/s/7p5a9ba0g9znac6/Sample.pbix?dl=0

 

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.