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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Creating Variances & Labels based on Prior Rows

Hello - I have a table with Years & Quarter # in Year, and parameters set up to select both (attaching sample data). I'm looking to create 2 things:

 

1. A custom column that labels, based on parameter, whether Qtr&Yr combination is Current Qtr&Current Yr, Prior Qtr&Current Yr, or Current Qtr&Prior Yr, like in table (assuming this could be done with Index column, i.e. 1 earlier is "Prior Qtr, Current Yr", and 4 earlier is "Current Qtr, Prior Year"?)

 

2. Variance measures to calculate the Q/Q variance of prior Qtr&Yr, and Y/Y variance of last year's Qtr&Yr

 

Would really appreciate the help - thanks!

 

 

FiscalYrFiscalQtrIdIndexValueCurrent/Prior Qtr Year?   
20203188.52    
20204251.94  Current Qtr ID2
20211355.57  Current Year2023
20212465.24    
20213564.14    
20214682.38    
2022173.63    
20222829.61Current Quarter, Prior Year   
2022391.48    
202241027.65    
202311153.09Prior Quarter, Current Year   
202321238.28Current Quarter, Current Year   
202331367.51    
202341486.49    
20241156.27    
202421666.65    
202431733.92    
202441844.64    

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_1-1679626657804.png

2. create measure with below dax formula

Current/Prior Qtr Year =
VAR _today =
    TODAY ()
VAR _year =
    YEAR ( _today )
VAR _qtr =
    QUARTER ( _today )
VAR _fiscayear =
    SELECTEDVALUE ( 'Table'[FiscalYr] )
VAR _fiscalqtr =
    SELECTEDVALUE ( 'Table'[FiscalQtrId] )
RETURN
    SWITCH (
        TRUE (),
        _fiscayear = _year
            && _fiscalqtr = _qtr, "Current qtr,Current year",
        _fiscayear = _year
            && _fiscalqtr = _qtr - 1, "Prior qtr,Current year",
        _fiscayear = _year - 1
            && _fiscalqtr = _qtr, "Current qtr,Prior year",
        _fiscayear = _year - 1
            && _fiscalqtr = _qtr - 1, "Prior qtr,Prior year"
    )
Q/Q =
VAR cur_id =
    SELECTEDVALUE ( 'Table'[Index] )
VAR cur_val =
    SELECTEDVALUE ( 'Table'[Value] )
VAR _val =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = cur_id - 1 )
    )
RETURN
    cur_val - _val
Prior Year Q/Q =
VAR _fy =
    SELECTEDVALUE ( 'Table'[FiscalYr] )
VAR _fqtr =
    SELECTEDVALUE ( 'Table'[FiscalQtrId] )
VAR _val =
    SELECTEDVALUE ( 'Table'[Value] )
VAR pre_val =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[FiscalYr] = _fy - 1
                && 'Table'[FiscalQtrId] = _fqtr
        )
    )
RETURN
    _val - pre_val

3. add a table visual with fields and measure

vbinbinyumsft_2-1679626685287.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_1-1679626657804.png

2. create measure with below dax formula

Current/Prior Qtr Year =
VAR _today =
    TODAY ()
VAR _year =
    YEAR ( _today )
VAR _qtr =
    QUARTER ( _today )
VAR _fiscayear =
    SELECTEDVALUE ( 'Table'[FiscalYr] )
VAR _fiscalqtr =
    SELECTEDVALUE ( 'Table'[FiscalQtrId] )
RETURN
    SWITCH (
        TRUE (),
        _fiscayear = _year
            && _fiscalqtr = _qtr, "Current qtr,Current year",
        _fiscayear = _year
            && _fiscalqtr = _qtr - 1, "Prior qtr,Current year",
        _fiscayear = _year - 1
            && _fiscalqtr = _qtr, "Current qtr,Prior year",
        _fiscayear = _year - 1
            && _fiscalqtr = _qtr - 1, "Prior qtr,Prior year"
    )
Q/Q =
VAR cur_id =
    SELECTEDVALUE ( 'Table'[Index] )
VAR cur_val =
    SELECTEDVALUE ( 'Table'[Value] )
VAR _val =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = cur_id - 1 )
    )
RETURN
    cur_val - _val
Prior Year Q/Q =
VAR _fy =
    SELECTEDVALUE ( 'Table'[FiscalYr] )
VAR _fqtr =
    SELECTEDVALUE ( 'Table'[FiscalQtrId] )
VAR _val =
    SELECTEDVALUE ( 'Table'[Value] )
VAR pre_val =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[FiscalYr] = _fy - 1
                && 'Table'[FiscalQtrId] = _fqtr
        )
    )
RETURN
    _val - pre_val

3. add a table visual with fields and measure

vbinbinyumsft_2-1679626685287.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.