Forum Discussion
Retrieving Values from Single Column
Hi,
I have the following simple table in my Datamodel:
Month Active caseload
01 March 2026 100
April 2026 125
May 2026 148
June 2026 178
July 2026 198
August 2026
September 2026
In order to retrieve the first Active Caseload figure of 100 I use this measure:
2026/2027 Start Total = FIRSTNONBLANK ( Caseload[Active Caseload], SUM ( Caseload[Active Caseload] ) )
Is this the best function to use?
I also want to retrieve the last figure (198) and the penultimate one(178) from the Active Caseload column, with the aim of using conditional formatting showing a triangle icon showing up / down, depending if the active Caseload rises or drops compared to the previous month in a Card visual.
What are the most efficient measures I should use to get something as simple as this?
Ps: I tried pasting my code into the 'Code' selector and it didn't work, I'm hoping this and other issues resolve themselves tomorrow when I have the Aug version installed. I cannot paste screenshots either so I've had to draw this table - what a mess.
Thanks
I have realised my mistake and deleted that post. I had also tried a solution as
Current Total = VAR _T = TOPN( 1, FILTER(CaseLoad,CaseLoad[Active Caseload]<>BLANK()), MONTH(CaseLoad[Month Year]),DESC) RETURN MAXX(_T,CaseLoad[Active Caseload])Previous Total = VAR _T = TOPN( 2, FILTER(CaseLoad,CaseLoad[Active Caseload]<>BLANK()), MONTH(CaseLoad[Month Year]),DESC) VAR _previous_date = MINX(_T,CaseLoad[Month Year]) RETURN CALCULATE(SUM(CaseLoad[Active Caseload]),CaseLoad[Month Year]=_previous_date)Is this a right approach.
12 Replies
- ShivekMaharajImpactful Individual
Hi ArchStanton,
Assuming Month is a proper Date column and you have one row per month, I would identify the latest two non-blank dates first rather than use FIRSTNONBLANK.
One small thing with the previous-value measure already posted: filtering to every date before the latest date and then taking MAX(Active Caseload) works with your sample because the values are increasing. If an older month had a higher caseload, it could return that instead of the immediately previous month.
I would use:
Current Total = VAR LatestDate = CALCULATE( MAX('Caseload'[Month]), FILTER( ALL('Caseload'), NOT ISBLANK('Caseload'[Active Caseload]) ) ) RETURN CALCULATE( MAX('Caseload'[Active Caseload]), 'Caseload'[Month] = LatestDate ) Previous Total = VAR LatestDate = CALCULATE( MAX('Caseload'[Month]), FILTER( ALL('Caseload'), NOT ISBLANK('Caseload'[Active Caseload]) ) ) VAR PreviousDate = CALCULATE( MAX('Caseload'[Month]), FILTER( ALL('Caseload'), 'Caseload'[Month] < LatestDate && NOT ISBLANK('Caseload'[Active Caseload]) ) ) RETURN CALCULATE( MAX('Caseload'[Active Caseload]), 'Caseload'[Month] = PreviousDate )With your example these return 198 and 178.
Then the comparison can simply be:
Caseload Change = [Current Total] - [Previous Total]and, if you want a triangle indicator:
Caseload Trend = SWITCH( TRUE(), [Caseload Change] > 0, UNICHAR(9650), [Caseload Change] < 0, UNICHAR(9660), UNICHAR(8212) )The current Power BI Card visual also supports reference labels and conditional formatting, so you could show the current value as the callout and the previous value/change underneath rather than needing separate visuals.
- aswathimohanAdvocate I
I have realised my mistake and deleted that post. I had also tried a solution as
Current Total = VAR _T = TOPN( 1, FILTER(CaseLoad,CaseLoad[Active Caseload]<>BLANK()), MONTH(CaseLoad[Month Year]),DESC) RETURN MAXX(_T,CaseLoad[Active Caseload])Previous Total = VAR _T = TOPN( 2, FILTER(CaseLoad,CaseLoad[Active Caseload]<>BLANK()), MONTH(CaseLoad[Month Year]),DESC) VAR _previous_date = MINX(_T,CaseLoad[Month Year]) RETURN CALCULATE(SUM(CaseLoad[Active Caseload]),CaseLoad[Month Year]=_previous_date)Is this a right approach.
- ArchStantonPower Participant
Hi, this has worked, thanks so much!
Before I mark this as a solution, I want to get to bottom why the other solution provided by an expert is failing.
- ArchStantonPower Participant
If I wanted the Triangles coloured Red for Up and Green for down, what would be the best way to do that?
My guess is to create another measure and use the Triangle measure in an IF statement?
- Ashish_MathurSuper User
Hi,
These are the measures
AC = SUM(Data[Active caseload]) Data available till = CALCULATE(max(Data[Month]),LASTNONBLANK('Calendar'[Date],CALCULATE([AC]))) First caseload value = CALCULATE([AC],firstNONBLANK('Calendar'[Date],CALCULATE([AC]))) Last caseload value = CALCULATE([AC],LASTNONBLANK('Calendar'[Date],CALCULATE([AC]))) Penultimate caseload value = CALCULATE([AC],CALCULATETABLE(LASTNONBLANK('Calendar'[Date],CALCULATE([AC])),DATESBETWEEN('Calendar'[Date],min('Calendar'[Date]),[Data available till]-1)))Hope this helps.
- ArchStantonPower Participant
Thanks for your help with this, 3 out of the 4 measures work, its the penultimate caseload measure thats failing. Please note that the Month Column within the Caseload table is a date field that is linked to my Date Calendar table.
Penultimate Caseload value = CALCULATE ( [Active Caseload Measure], CALCULATETABLE ( LASTNONBLANK (Caseload[Month], CALCULATE ( [Active Caseload Measure] ) ), DATESBETWEEN ( Caseload[Month], MIN ( Caseload[Month] ), [Data available till] - 1 ) ) )- Ashish_MathurSuper User
Hi,
Share the download link of your PBI file with your formulas already written there.
- v-achippaCommunity Support
Hi ArchStanton,
Thank you for reaching out to Microsoft Fabric Community.
Thank you Praful_Potphode, ShahRukhSameer, Ashish_Mathur and ShivekMaharajGilbertQ for the prompt response.
As we haven’t heard back from you, we wanted to kindly follow up to check if the response provided by the user's for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa - ArchStantonPower Participant
I've retrieved the latest figure using this DAX which works, how can I get the value before it (the prior month)?
Current Total =
VAR _lastdate =
CALCULATE(MAX('Caseload'[Month]),
FILTER('Caseload','Caseload'[Active Caseload] <> BLANK() )
)
RETURN
CALCULATE(
MAX('Caseload'[Active Caseload]),
FILTER('Caseload', 'Caseload'[Month] = _lastdate)
)
- ShahRukhSameerHelper V
Hi ArchStanton,
I’d probably avoid FIRSTNONBLANK for this. Since you want the first/latest available value based on the month, it’s better to use the date column to determine which row you want.
For example, for the latest non-blank value:
Latest Caseload = CALCULATE( MAX(Caseload[Active Caseload]), TOPN( 1, FILTER( ALL(Caseload[Month]), NOT ISBLANK(Caseload[Active Caseload]) ), Caseload[Month], DESC ) )
This would return 198 in your example.
Then you can get the previous available value (178) and compare the two:
Caseload Change = [Latest Caseload] - [Previous Caseload]
Use Caseload Change for the conditional formatting — positive = up, negative = down.
The important thing is that Month should be a proper Date column rather than text.
And hopefully the August update fixes some of the Community posting issues too — having to draw the table manually certainly makes things harder! 🙂
- Praful_PotphodeSuper User
Hi ArchStanton
Please try below code
Latest Non-Blank Month = CALCULATE ( MAX ( 'Caseload'[Month] ), FILTER ( ALL ( 'Caseload'[Month] ), NOT ISBLANK ( 'Caseload'[Active Caseload] ) ) ) Previous Non-Blank Month = CALCULATE ( MAX ( 'Caseload'[Month] ), FILTER ( ALL ( 'Caseload'[Month] ), 'Caseload'[Month] < [Latest Non-Blank Month] && NOT ISBLANK ( 'Caseload'[Active Caseload] ) ) ) Current Total = CALCULATE ( SUM ( 'Caseload'[Active Caseload] ), 'Caseload'[Month] = [Latest Non-Blank Month] ) Previous Total = CALCULATE ( SUM ( 'Caseload'[Active Caseload] ), 'Caseload'[Month] = [Previous Non-Blank Month] ) Caseload Trend = VAR Delta = [Current Total] - [Previous Total] RETURN IF ( ISBLANK ( [Current Total] ) || ISBLANK ( [Previous Total] ), BLANK (), Delta )Please give kudos or mark it as solution once confirmed.
Thanks and Regards,
Praful