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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
di12
Frequent Visitor

Week over week comparison for matrix

This should be very easy, but I did not manage to get solution.

 

I have 3 columns of data: Name , Amount, Date

 

I would like to have a pivot at the end with week over week comparison, i.e. like in below matrix

------- week 21 | WoW | week 22 | WoW | week23

Jack       100         20%        120        -50%    60

John      10           20%         12        -50%    6

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your data model looks like, but please check the below picture and the attached pbix file.

I tried to create a sample pbix file.

I suggest having a dim-calendar table that contains week information, like the attached.

I hope this sample can help to get your own solution for your own data model.

 

Untitled.png

 

Amount total: = 
SUM( Data[Amount] )

 

current wk vs prior wk: = 
VAR _currentwkamount = [Amount total:]
VAR _currentwkenddate =
    MAX ( 'Calendar'[End of Week] )
VAR _priorwkenddate = _currentwkenddate - 7
VAR _priorwkamount =
    CALCULATE (
        [Amount total:],
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[End of Week] = _priorwkenddate )
    )
RETURN
    IF (
        HASONEVALUE ( 'Calendar'[WK-Year] ),
        DIVIDE ( _currentwkamount - _priorwkamount, _priorwkamount )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your data model looks like, but please check the below picture and the attached pbix file.

I tried to create a sample pbix file.

I suggest having a dim-calendar table that contains week information, like the attached.

I hope this sample can help to get your own solution for your own data model.

 

Untitled.png

 

Amount total: = 
SUM( Data[Amount] )

 

current wk vs prior wk: = 
VAR _currentwkamount = [Amount total:]
VAR _currentwkenddate =
    MAX ( 'Calendar'[End of Week] )
VAR _priorwkenddate = _currentwkenddate - 7
VAR _priorwkamount =
    CALCULATE (
        [Amount total:],
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[End of Week] = _priorwkenddate )
    )
RETURN
    IF (
        HASONEVALUE ( 'Calendar'[WK-Year] ),
        DIVIDE ( _currentwkamount - _priorwkamount, _priorwkamount )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.