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

Comparing the change of week in different categories under the same table and columns

Hi all,

I have this table below and I am using a dropdown list to select different report dates. I am trying to compare if there are changes of week within the same order number. For example, we can see that for PO2, the week changes from 1 to 7 in the corresponding report date (18-Feb and 2-Mar).

 

arthur_limewa_0-1649929415913.png

 

I want to display the Count of Order number and the sum of Qty in which that the same order number changes its week given two dates. This is a sample display that I want to show:

arthur_limewa_1-1649929427141.pngarthur_limewa_2-1649929431810.png

May I know whether any DAX measures would help this calculation?

Many Thanks.

7 REPLIES 7
Anonymous
Not applicable

HI @Anonymous,

You can try to use the following measure formulas if they are suitable for your requirement:

Count of Order =
VAR currDate =
    MAX ( Table[Date] )
VAR weekstart =
    currDate - WEEKDAY ( currDate, 2 ) + 1
VAR currGroup =
    SELECTEDVALUE ( NewTable[Group] )
VAR week_offset =
    LOOKUPVALUE ( NewTable[lookup_table], NewTable[Group], currGroup )
VAR prevDate =
    DATE ( YEAR ( weekstart ), MONTH ( weekstart ), DAY ( weekstart ) - week_offset * 7 )
RETURN
    CALCULATE (
        COUNTROWS ( VALUES ( Table[Order Number] ) ),
        FILTER (
            ALL ( Table ),
            YEAR ( [ReportDate] ) = YEAR ( prevDate )
                && WEEKNUM ( [ReportDate], 2 ) = WEEKNUM ( prevDate, 2 )
        )
    )

Sum of Qty =
VAR currDate =
    MAX ( Table[Date] )
VAR weekstart =
    currDate - WEEKDAY ( currDate, 2 ) + 1
VAR currGroup =
    SELECTEDVALUE ( NewTable[Group] )
VAR week_offset =
    LOOKUPVALUE ( NewTable[lookup_table], NewTable[Group], currGroup )
VAR prevDate =
    DATE ( YEAR ( weekstart ), MONTH ( weekstart ), DAY ( weekstart ) - week_offset * 7 )
RETURN
    CALCULATE (
        SUM ( Table[Qty] ),
        FILTER (
            ALL ( Table ),
            YEAR ( [ReportDate] ) = YEAR ( prevDate )
                && WEEKNUM ( [ReportDate], 2 ) = WEEKNUM ( prevDate, 2 )
        )
    )

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi Xiaoxin,

 

Thanks for your reply. I tried to incorporate the measures into the dashboard however it seems like it doesn't show the groups of the lookup_value table, instead it sums up into a single category. Are there anything else I need to add? I tried to add the group to the legend as well but it returns an error. The below picture is for your reference.

 

arthur_limewa_0-1650872093709.png

Thanks.

 

Best,

Arthur

Anonymous
Not applicable

HI @Anonymous,

You need to use the 'week group' field axis of your chart, then measure can get corresponding results based on the current group.

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi @ghoshabhijeet,

Thanks for your reply. For the X-axis of the charts, I categorize the week changes by incorporating vlookup function in excel as follows:

arthur_limewa_0-1649931893014.png

 

For value equal or bigger than 4, I categorize it as more than plus 3 weeks and a similar approach for week changes equal or less than -4.

@Anonymous  Thanks for sharing the categories. Would you be able to share some sample data ?

Anonymous
Not applicable

Hey @ghoshabhijeet,

Yes, I can provide some sample data in the below link:

 

PBI Sample Data

 

Thanks.

 

 

ghoshabhijeet
Solution Supplier
Solution Supplier

@Anonymous  What are the categories/buckets which you are showing in the X-Axis of the charts ?

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.