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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
m4xon
Helper III
Helper III

Get value from 'previous' row that was calculated by measure

Hello,

 

I have following problem, I need to calculate a specific value, but to do that each time I have to use as a part of calculation a value from the prior row (based on the q-yyyy). I have in a table column from source table [Quarters] and I added one measure to count total rows

Total = CALCULATE ( COUNTROWS ( dimSource ), dimSource[Action] = "OK" )

and now I need a measure that will calculate something extra but using the "total" from previous measure and previous row 🙂

Indx = 
VA
R _a =
    CALCULATE (
        MAX ( 'dimSource'[Quarter] ),
        FILTER (
            ALL('dimSource'),
            [Quarter] < MAX ( 'dimSource'[Quarter] )
        )
    )

VAR _result =
CALCULATE (
        MAX ( 'dimSource'[Quarter] ),
        FILTER (
            ALL ('dimSource'),
            [Quarter] = _a
        )
    )
RETURN
    _result

Based on the above I get a formula which returns to me what is the preceding quarter, but I need a total value instead of quater 

Screenshot 2023-07-05 145908.png

1 ACCEPTED SOLUTION

@m4xon 

 

Try this:

 

 

Total = 
VAR LastQuarter =
    CALCULATE (
        MAX ( 'dimSource'[Quarter] ),
        FILTER (
            ALL('dimSource'), 
            [Quarter] < MAX ( 'dimSource'[Quarter] )
        )
    )
VAR StagingTable = FILTER(ALLSELECTED(dimSource),[Action]="OK" && [Quarter] = LastQuarter)

VAR _result =  SELECTCOLUMNS(SUMMARIZE(StagingTable,
                                    [Quarter],
                                    "Count",CALCULATE(COUNTROWS (StagingTable))
                            ),
               "Total",MIN([Count]))

RETURN
    _result

 

 



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!

View solution in original post

4 REPLIES 4
m4xon
Helper III
Helper III

works like a dream, thanks!

Nathaniel_C
Community Champion
Community Champion

Hi @m4xon ,
If I understand the problem, replace the quarter value with the total value, and replace the = with<=

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel


VAR _result =
CALCULATE (
        MAX ( 'dimSource'[Total] ),
        FILTER (
            ALL ('dimSource'),
            [Quarter] < = _a
        )
    )

 





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

Proud to be a Super User!




Hello,

It would be to easy 😉 We don't have a column [Total], it's a measure. In base table we have only [Quarter], this is the question, how to put a measure into it.

 

Thanks!

Max

@m4xon 

 

Try this:

 

 

Total = 
VAR LastQuarter =
    CALCULATE (
        MAX ( 'dimSource'[Quarter] ),
        FILTER (
            ALL('dimSource'), 
            [Quarter] < MAX ( 'dimSource'[Quarter] )
        )
    )
VAR StagingTable = FILTER(ALLSELECTED(dimSource),[Action]="OK" && [Quarter] = LastQuarter)

VAR _result =  SELECTCOLUMNS(SUMMARIZE(StagingTable,
                                    [Quarter],
                                    "Count",CALCULATE(COUNTROWS (StagingTable))
                            ),
               "Total",MIN([Count]))

RETURN
    _result

 

 



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!

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