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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Sebllo
Frequent Visitor

How to : Get last value of date by category

Hello, 

 

I'm realy stuck and I have spent long time on this point... 

 

I would like to know how can I get the last value of a day for a category. 

Let's take this example : 

 

Sebllo_0-1610650104444.png

 

As you can see we have 3 categories : A, B and C and we have 3 dates but 2 days. Two datetime are on 14.01.2021 and one datetime on 15.01.2021. 

So I would like to calculate the column LastByCat with a measure that will repeat the last value for a category by day as shown in my screen. 

 

Can you please help me on this. 

 

Thx all. 

Best

 

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

@Sebllo 

Here is one way, though it involves a number of steps:

1) Create a new column for the date (and set the field type to Date):

Date column.JPG

 2) create measure for the sum of the scores:

 

Sum Score = SUM(FactTable[Score])

 

3) Create a measure to find the max value by date:

 

Max Score by Cat and date = 
VAR seldate = SELECTEDVALUE(FactTable[Date])
VAR MaxValue = MAXX(FILTER(ALLEXCEPT(FactTable, FactTable[Cat]), 
                FactTable[Date] = seldate), 
                [DateTime])
RETURN
CALCULATE([Sum Score], 
        FILTER(FactTable, FactTable[DateTime] = MaxValue))

 

 4) the final measure to return the [Max Score by Cat and date] for each category:

 

Final Measure= 
VAR seldate = SELECTEDVALUE(FactTable[Date])
RETURN
CALCULATE([Max Score by Cat and date], 
            FILTER(ALLEXCEPT(FactTable, FactTable[Cat]), 
                FactTable[Date] = seldate))

 

Which gets you this:

result.JPG

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

11 REPLIES 11
Anonymous
Not applicable

Hi Buddy, maybe it can help you.  It is a simple solution using TOP N filters by Date.

 

https://www.youtube.com/watch?v=q1GE9orj7Qk

 

best!

PaulDBrown
Community Champion
Community Champion

@Sebllo 

Here is one way, though it involves a number of steps:

1) Create a new column for the date (and set the field type to Date):

Date column.JPG

 2) create measure for the sum of the scores:

 

Sum Score = SUM(FactTable[Score])

 

3) Create a measure to find the max value by date:

 

Max Score by Cat and date = 
VAR seldate = SELECTEDVALUE(FactTable[Date])
VAR MaxValue = MAXX(FILTER(ALLEXCEPT(FactTable, FactTable[Cat]), 
                FactTable[Date] = seldate), 
                [DateTime])
RETURN
CALCULATE([Sum Score], 
        FILTER(FactTable, FactTable[DateTime] = MaxValue))

 

 4) the final measure to return the [Max Score by Cat and date] for each category:

 

Final Measure= 
VAR seldate = SELECTEDVALUE(FactTable[Date])
RETURN
CALCULATE([Max Score by Cat and date], 
            FILTER(ALLEXCEPT(FactTable, FactTable[Cat]), 
                FactTable[Date] = seldate))

 

Which gets you this:

result.JPG

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thanks a lot. Your support has helped me a lot.

Thank a lot @PaulDBrown 

It's working perfectly! 

 

The only point, maybe it's a stupid question is that I cannot use the Final Measure in a Chart... This measure works properly on a table but when I try to use it as value on a chart, it stay empty. 

 

I have checked the Data Type of the Measure and it's correctly set to Whole Number... 

 

 

Sebllo_0-1610981332797.png

 

Any idea ?? Thx again!

 

@Sebllo 

Seeing as the measure calculates based on date and date/time fields, you probably need to a chart which has these in the axis. Something along these lines, though it depends what you are trying to show 

Captura.JPG

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






@PaulDBrown  You're right, when I'm adding the date on Axis the measure is take in consideration and I can see data on chart. But in my case, I need to create a simple Radar Chart where the Category is my column Category and Y axis (values) is the Average of my Final Measure.... 

Something like that : 

 

Sebllo_0-1610985976349.png

 

 

 

@Sebllo 

Can you define what you mean by the average of the final measure? The average of dates? the average of date/times? if so, which dates or date/times (since the Radar chart doesn't have any dates as a filter context)?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






I'm sorry and thanks to your reply I understood my mistake. 

Now, I've just added a slicer filter based on date because the chart can work for a single day only. And now it works perfectly. 

 

The Radar Chart must display the last score by cat for each day. Now it's ok !"

 

Thx again !!! 

Sebllo
Frequent Visitor

Sorry to insist, but does anyone have an idea? I am really stuck to finish my report ... Thank you !!

@amitchandak  ? 

amitchandak
Super User
Super User

@Sebllo , Try a new measure like

calculate(lastnonblankvalue(Table[date], max(Table[Score])), allexcept(Table, Table[Cat]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  thanks for your reply.

This measure seems to calculate the max date of my dataset. But what I need is the calculation of the column LastByCat of my example above. 

 

For each single day, I would like to get the score value of the last DateTime for a category and repeat it for each DateTime of the same day. 

 

As you can see on my example for the day 14.01.2021 we have two datetime. One at 14:17 and another one at 18h24. I want to get the Cat values of 18h24 (the last datetime) and put it for corresponding cat of 14h17 group. And this day by day. For 15.01.2021 I have only one datetime, so it takes these values. 

 

Is it more clear ? Thanks again for your precious help ! 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors