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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
harish_2203
New Member

calculate two adjacent columns based on two different time spans in a matrix visual

Hi all,

 

I need a support in power BI. I have datewise data for a month but more data can be added further.

 

Now I need to create a matrix visual where I have differnet calculated measures on row and different columns based on two different date spans and its difference. Date spans are not of fixed duration and they may changed later on. Example image added.

 

 

 

Thanks in advance.Capture.JPG

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @harish_2203,

I'd like to suggest you do unpivot column on these value fields to convert them to Attribute and Value. 

Unpivot columns - Power Query | Microsoft Learn

Then you can use the 'Attribute' on the row, 'date' field on the column to design matrix visual. (you can create a slicer with date field to control which date range of records displayed on matrix)

After these steps, you can create a measure formula with if statement to check current hierarchy level to redirect different expressions to aggregated value field values(detail level) or calculate the difference based on detail level.

formula =
VAR _start =
    MIN ( Table1[Date] )
VAR _end =
    MAX ( Table1[Date] )
RETURN
    IF (
        HASONEVALUE ( Table[Date] ),
        SUM ( Table[Value] ),
        CALCULATE (
            CALCULATE ( SUM ( Table1[Value] ), [Date] = _end )
                - CALCULATE ( SUM ( Table1[Value] ), [Date] = _start ),
            ALLSELECTED ( Table1 ),
            VALUES ( Table1[Attribute] )
        )
    )

Regards,

Xiaoxin Sheng

View solution in original post

7 REPLIES 7
harish_2203
New Member

Sample excel raw data and PBI snapshot.

 

harish_2203_0-1713336454497.pngharish_2203_1-1713336494148.png

 

 

 

 

 

Anonymous
Not applicable

Hi @harish_2203,

I'd like to suggest you do unpivot column on these value fields to convert them to Attribute and Value. 

Unpivot columns - Power Query | Microsoft Learn

Then you can use the 'Attribute' on the row, 'date' field on the column to design matrix visual. (you can create a slicer with date field to control which date range of records displayed on matrix)

After these steps, you can create a measure formula with if statement to check current hierarchy level to redirect different expressions to aggregated value field values(detail level) or calculate the difference based on detail level.

formula =
VAR _start =
    MIN ( Table1[Date] )
VAR _end =
    MAX ( Table1[Date] )
RETURN
    IF (
        HASONEVALUE ( Table[Date] ),
        SUM ( Table[Value] ),
        CALCULATE (
            CALCULATE ( SUM ( Table1[Value] ), [Date] = _end )
                - CALCULATE ( SUM ( Table1[Value] ), [Date] = _start ),
            ALLSELECTED ( Table1 ),
            VALUES ( Table1[Attribute] )
        )
    )

Regards,

Xiaoxin Sheng

harish_2203
New Member

harish_2203
New Member

Please download the pbix file from the below link.

 

test.pbix - Google Drive

Anonymous
Not applicable

Hi @harish_2203,

It seems like I can't view the share link, can you please create some dummy data and paste them here with table format? Then we can simply copy them to power bi side and test and coding formula on it.

Regards,
Xiaoxin Sheng

Anonymous
Not applicable

Hi @harish_2203 ,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

harish_2203
New Member

@lbendlin @Ritaf1983 @amitchandak Kindly suggest any solution. Thanks in advance.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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