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
joshuac055
Regular Visitor

Create a Table that compares two different weeks of data stored in the same table

Hello, I am trying to create a table that would compare two different weeks of data that are currently stored in the same table.

Here's an example data set: 

DateLocationProductTotal LBsTotal $'s
4/27/20241A10 $ 100.00
4/27/20242A9 $   95.00
4/27/20242B11 $ 102.00
4/27/20243C8 $   86.00
4/20/20241A12 $ 105.00
4/20/20242A11 $ 100.00
4/20/20242B13 $ 107.00
4/20/20243C10 $   91.00
4/13/20241A14 $ 110.00
4/13/20242A13 $ 105.00
4/13/20242B15 $ 112.00
4/13/20243C12 $   96.00

 

I want to be able to then create a table or visual that would compare the total lbs and $s for each location and product. Lets say for example I wanted to compare 4/27 with 4/13 it would look like this:

LocationProductTotal LBs differenceTotal $'s difference
1A-4-10
2A-4-10
2B-4-10
3C-4-10

 

Ideally, the visual I create on my report would have a slicer that lets you choose the two weeks you are comparing, but I do not know if that is even possible. If that is not possible, I would like to start with just comparing two weeks and that table can be static. Would appreciate any help. Thanks!

 

2 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@joshuac055 

here is a workaround for you

11.PNG

pls see the attachment below





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

Proud to be a Super User!




View solution in original post

@ryan_mayu Thanks for your contribution on this thread.

Hi @joshuac055 ,

@ryan_mayu provided you a pbix file with the solution, did you check that? If it can help you get the expected result? If yes, you can mark his post as the solution. Thank you.

Otherwise, you can create two measures as below to get it. Please find the details in the attachment.

Total $'s difference = 
VAR _minweek =
    MIN ( 'Table'[Date] )
VAR _maxweek =
    MAX ( 'Table'[Date] )
VAR _mints =
    CALCULATE (
        SUM ( 'Table'[Total $'s] ),
        FILTER ( 'Table', 'Table'[Date] = _minweek )
    )
VAR _maxts =
    CALCULATE (
        SUM ( 'Table'[Total $'s] ),
        FILTER ( 'Table', 'Table'[Date] = _maxweek )
    )
RETURN
    _maxts - _mints
Total LBs difference = 
VAR _minweek =
    MIN ( 'Table'[Date] )
VAR _maxweek =
    MAX ( 'Table'[Date] )
VAR _minLB =
    CALCULATE (
        SUM ( 'Table'[Total LBs] ),
        FILTER ( 'Table', 'Table'[Date] = _minweek )
    )
VAR _maxLB =
    CALCULATE (
        SUM ( 'Table'[Total LBs] ),
        FILTER ( 'Table', 'Table'[Date] = _maxweek )
    )
RETURN
    _maxLB - _minLB

vyiruanmsft_0-1714459975919.png

Best Regards

Community Support Team _ Rena
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

8 REPLIES 8
ryan_mayu
Super User
Super User

@joshuac055 

here is a workaround for you

11.PNG

pls see the attachment below





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

Proud to be a Super User!




Hello, I was able to test this this morning. However, I get an error with the forumula in regards to the Max function. In error, I had my test data using numerial values for the location when in reality it is a name. I think I will need to adjust the formula for this. 

It won't let me open the file because it's on a newer version of the PowerBI app. It takes my org forever to reply to a request to update apps. Do you have another file I could use?

I don't have other file. Do you have another laptop that can install the new version?





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

Proud to be a Super User!




I will try on my PC at home later today.

@ryan_mayu Thanks for your contribution on this thread.

Hi @joshuac055 ,

@ryan_mayu provided you a pbix file with the solution, did you check that? If it can help you get the expected result? If yes, you can mark his post as the solution. Thank you.

Otherwise, you can create two measures as below to get it. Please find the details in the attachment.

Total $'s difference = 
VAR _minweek =
    MIN ( 'Table'[Date] )
VAR _maxweek =
    MAX ( 'Table'[Date] )
VAR _mints =
    CALCULATE (
        SUM ( 'Table'[Total $'s] ),
        FILTER ( 'Table', 'Table'[Date] = _minweek )
    )
VAR _maxts =
    CALCULATE (
        SUM ( 'Table'[Total $'s] ),
        FILTER ( 'Table', 'Table'[Date] = _maxweek )
    )
RETURN
    _maxts - _mints
Total LBs difference = 
VAR _minweek =
    MIN ( 'Table'[Date] )
VAR _maxweek =
    MAX ( 'Table'[Date] )
VAR _minLB =
    CALCULATE (
        SUM ( 'Table'[Total LBs] ),
        FILTER ( 'Table', 'Table'[Date] = _minweek )
    )
VAR _maxLB =
    CALCULATE (
        SUM ( 'Table'[Total LBs] ),
        FILTER ( 'Table', 'Table'[Date] = _maxweek )
    )
RETURN
    _maxLB - _minLB

vyiruanmsft_0-1714459975919.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This works except for one small thing. I did not mention that one week a location could have one product and a few weeks later it could have two products. I would like it to be able to compare those two weeks by product even if one week is missing a product. Let me know if that does not make sense.

Hi @joshuac055 ,

I'm not clear about your above requirement, could you please provide some examples to explain the calculation logic and final expected result? Thank you.

one week a location could have one product and a few weeks later it could have two products. I would like it to be able to compare those two weeks by product even if one week is missing a product

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.