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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ADSL
Post Prodigy
Post Prodigy

Calculate & Comparison Current Week of Month with Last Month of Week

Hi BI Community Team,

 

I have a sales order table that contain data 02 months - Nov'23 & Dec'23. With this data, I am standing in Dec'23 by week then want to see and compare with last month by week as the screenshot below. 

 

Example:  W1-Dec vs W1-Nov | W2-Dec vs W2-Nov

 

Any suggestion/advise? 

 

2023-12-08_16-11-47.jpg

1 ACCEPTED SOLUTION

Considering you'll need to calculate the last month, I think we should use month number in the measure.

I've also modified the measure a little bit as below.

 

Total Sales Same Week Last Month2 = 
VAR _SameWeek = SELECTEDVALUE('Calendar'[Week of Month])
VAR _LastMonth = IF(SELECTEDVALUE('Calendar'[MonthOfYear])= 1, 12, SELECTEDVALUE('Calendar'[MonthOfYear]) -1)
VAR _LastMonthYear = IF(SELECTEDVALUE('Calendar'[MonthOfYear])= 1, SELECTEDVALUE('Calendar'[Year])-1, SELECTEDVALUE('Calendar'[Year]))
RETURN 
IF( CALCULATE( SUM('Sales Order'[Amt No VAT]), 'Calendar'[Week of Month] = _SameWeek) >0,
CALCULATE( SUM('Sales Order'[Amt No VAT]), FILTER(ALL('Calendar'), 'Calendar'[Week of Month] = _SameWeek && 'Calendar'[MonthOfYear] = _LastMonth && 'Calendar'[Year] = _LastMonthYear)),
BLANK())

 

Best Regards,

Joyce

View solution in original post

6 REPLIES 6
mh2587
Super User
Super User

WoW Sales Comparison = //Try this one might help you
VAR CurrentFirstWeekSale =
    CALCULATE ( [Total Sales], 'Calendar'[WeekNumber of Month] = 1 )
VAR PreviouseFirstWeekSale =
    CALCULATE (
        [Total Sales],
        DATEADD ( 'Calendar'[Date], -1, MONTH ),
        'Calendar'[WeekNumber of Month] = 1
    )
RETURN
    CurrentFirstWeekSale - PreviouseFirstWeekSale

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



isjoycewang
Super User
Super User

Hi @ADSL,

 

Please see attached demo file here.

You can create another measure and add it into the clustered column chart as below.

Total Sales Same Week Last Month = 
VAR _week = SELECTEDVALUE('Calendar'[Week of Month])
VAR _month = SELECTEDVALUE('Calendar'[Date].[MonthNo])
RETURN 
CALCULATE( SUM('Sales Order'[Amt No VAT]), FILTER(ALL('Calendar'), 'Calendar'[Week of Month] = _week && 'Calendar'[Date].[MonthNo] = _month-1))

 

If you only want to see Nov data when you have Dec data:

Total Sales Same Week Last Month = 
VAR _week = SELECTEDVALUE('Calendar'[Week of Month])
VAR _month = SELECTEDVALUE('Calendar'[Date].[MonthNo])
RETURN 
IF( CALCULATE( SUM('Sales Order'[Amt No VAT]), 'Calendar'[Week of Month] = _week) >0,
CALCULATE( SUM('Sales Order'[Amt No VAT]), FILTER(ALL('Calendar'), 'Calendar'[Week of Month] = _week && 'Calendar'[Date].[MonthNo] = _month-1)),
BLANK())

 

isjoycewang_0-1702029342452.png

 

Best Regards,

Joyce

 

Hi @isjoycewang,

 

Thank you for your helpful feedback. 

 

If we want to change the slicer of month to "MonthInCalendar" as the screenshot below.

 

Any suggestion to revise the measure?

 

2023-12-13_09-08-20.jpg

 

Best Regards,

Considering you'll need to calculate the last month, I think we should use month number in the measure.

I've also modified the measure a little bit as below.

 

Total Sales Same Week Last Month2 = 
VAR _SameWeek = SELECTEDVALUE('Calendar'[Week of Month])
VAR _LastMonth = IF(SELECTEDVALUE('Calendar'[MonthOfYear])= 1, 12, SELECTEDVALUE('Calendar'[MonthOfYear]) -1)
VAR _LastMonthYear = IF(SELECTEDVALUE('Calendar'[MonthOfYear])= 1, SELECTEDVALUE('Calendar'[Year])-1, SELECTEDVALUE('Calendar'[Year]))
RETURN 
IF( CALCULATE( SUM('Sales Order'[Amt No VAT]), 'Calendar'[Week of Month] = _SameWeek) >0,
CALCULATE( SUM('Sales Order'[Amt No VAT]), FILTER(ALL('Calendar'), 'Calendar'[Week of Month] = _SameWeek && 'Calendar'[MonthOfYear] = _LastMonth && 'Calendar'[Year] = _LastMonthYear)),
BLANK())

 

Best Regards,

Joyce

Hi @isjoycewang,

 

Thank you for your valuable feebback and helup. 

 

All your measure are working, just want to change the slicer of month to choose month & year.

 

Best Regards,

Glad to help!

The measure should work whether you use [MonthNo] or [MonthInCalendar] in the slicer.

Since the first month in a year might cause BLANK in the chart, provided above updated measure for your reference.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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