Forum Discussion

ArchStanton's avatar
ArchStanton
Power Participant
12 days ago
Solved

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

  • aswathimohan's avatar
    aswathimohan
    12 days ago

    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

  • ShivekMaharaj's avatar
    ShivekMaharaj
    Impactful 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.

    • aswathimohan's avatar
      aswathimohan
      Advocate 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.

      • ArchStanton's avatar
        ArchStanton
        Power 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.

    • ArchStanton's avatar
      ArchStanton
      Power 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?

  • 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.

    • ArchStanton's avatar
      ArchStanton
      Power 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_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

        Share the download link of your PBI file with your formulas already written there.

  • ArchStanton's avatar
    ArchStanton
    Power 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)

                        )

  • 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! 🙂

  • 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