cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
anil Member
Member

Re: Last 3 days average values per ID using date

Hi Greg,

               Thanks for the reply.

I am getting incorrect results when used the calculation provided by you. Please look into the attached PBIX.

 PBIX file: https://www.dropbox.com/s/2bu5kt1l6k3nlvy/SampleT3.pbix?dl=0

 

 

E1.JPGE2.JPGE3.JPG 

 

 

 

 PBIX file: https://www.dropbox.com/s/2bu5kt1l6k3nlvy/SampleT3.pbix?dl=0

Super User
Super User

Re: Last 3 days average values per ID using date

Not sure, it was working in the PBIX I attached to the last reply.


I have book! Learn Power BI from Packt


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Super User
Super User

Re: Last 3 days average values per ID using date

OK, first, you need to clean up your PBIX, you have some columns causing circular dependencies, like "If test". Get rid of that column. Also, for some odd reason it wasn't getting the correct modelcode at the beginning so I fixed that and cleaned up some code.

 

Last 3TEst = 
VAR __modelcode = MAXX(CALCULATETABLE('Hyster'),'Hyster'[modelcode])
VAR __tmpTable = SUMMARIZE(FILTER(ALL('Hyster'),Hyster[modelcode]=__modelcode),[Order Date],[Bucket])
VAR __maxDate = MAXX(__tmpTable,[Order Date])
VAR __tmpTable2 = TOPN(3,__tmpTable,[Order Date],DESC)
VAR __tmpTable3 = SELECTCOLUMNS(__tmpTable2,"__Bucket",[Bucket])
RETURN
IF(
    CONTAINS(__tmpTable3,[__Bucket],"Green"), "Green", 
    IF(
        CONTAINS(__tmpTable3,[__Bucket],"Yellow"), 
        "Yellow", 
        "Red"
    )
)

 


I have book! Learn Power BI from Packt


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

anil Member
Member

Re: Last 3 days average values per ID using date

Dear Greg, Thank you so much. Now everything is working fineSmiley Very Happy

It's very kind of you Sir.

Super User
Super User

Re: Last 3 days average values per ID using date

Yeah, I forgot that since you are using a calculated column that the first variable has to be calculated a little differently. Glad we got there.


I have book! Learn Power BI from Packt


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

anil Member
Member

Re: Last 3 days average values per ID using date

Greg,

        Is it possible to color code the created column based on the result.Eg if its Green then green color, if Yellow yello color else Red color.

        I am unable to create measure using the calculated column. If we assign a number to each result of the column. Using that we can color the column.

Super User
Super User

Re: Last 3 days average values per ID using date

That code should work as a measure. You might change the first variable to a simple MAX of the column. I'll have to check, on my phone at the moment.

I have book! Learn Power BI from Packt


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

anil Member
Member

Re: Last 3 days average values per ID using date

Thanks Greg, I have created measure and using it colored the column.

anil Member
Member

Re: Last 3 days average values per ID using date

Hi Greg,

             If we want to slice by date and by selected month can we calculate last 3 days results?

Helpful resources

Announcements
Community Highlights

Community Highlights

Find out what's new in the Power BI Community!

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 95 members 1,544 guests
Please welcome our newest community members: