Forum Discussion
DAX Calculation based on MTD and Operating days for current and previous year dynamically for months
- 1 year ago
Measure 1: DWH Revenue per Operating Day (Feb 2024)
DWH_Revenue_Per_Op_Day_Feb_24 = VAR Revenue_Feb_24 = CALCULATE( SUM(DWH_Fact[Revenue]), 'Date_Working'[Year] = 2024, 'Date_Working'[Month] = "February") VAR Operating_Days_Feb_24 = LOOKUPVALUE('Date_Working'[DE Op Days], 'Date_Working'[Year], 2024, 'Date_Working'[Month], "February") RETURN IF(Operating_Days_Feb_24 <> 0, Revenue_Feb_24 / Operating_Days_Feb_24, BLANK())Measure 2: DWH Revenue per Adjusted Operating Day (Feb 2025 MTD)
DWH_Revenue_Per_Adj_Op_Day_Feb_25 = VAR CurrentDate = MAX(DWH_Fact[Date]) VAR Revenue_Feb_25_MTD = CALCULATE( SUM(DWH_Fact[Revenue]), 'Date_Working'[Year] = 2025, 'Date_Working'[Month] = "February", DWH_Fact[Date] <= CurrentDate ) VAR Op_Days_Until_Today = CALCULATE( COUNTROWS('Date_Working'), 'Date_Working'[Year] = 2025, 'Date_Working'[Month] = "February", 'Date_Working'[Date] <= CurrentDate, NOT(WEEKDAY('Date_Working'[Date],2) IN {6,7}) ) VAR Total_Op_Days_Feb_25 = LOOKUPVALUE('Date_Working'[DE Op Days], 'Date_Working'[Year], 2025, 'Date_Working'[Month], "February") VAR AdjustedRevenue = (Revenue_Feb_25_MTD / Op_Days_Until_Today) * Total_Op_Days_Feb_25 RETURN IF(Op_Days_Until_Today <> 0, AdjustedRevenue, BLANK()) - Anonymous1 year ago
Hi, bhaskarpbi999
Perhaps you can refer to the following DAX to create Measure:
First Measure:
DWH_Revenue_Feb_2024_Per_Op_Day = VAR Revenue_Feb_2024 = CALCULATE( SUM('DWH Fact Table'[Revenue]), 'Date Working Table'[Year] = 2024, 'Date Working Table'[Month] = "February" ) VAR Operating_Days_Feb_2024 = CALCULATE( SUM('Date Working Table'[This Year DE Op Days]), 'Date Working Table'[Year] = 2024, 'Date Working Table'[Month] = "February" ) RETURN DIVIDE(Revenue_Feb_2024, Operating_Days_Feb_2024)Second Measure:
DWH_Revenue_Feb_2025_MTD_Adjusted = VAR CurrentDate = TODAY() VAR Revenue_Feb_2025_MTD = CALCULATE( SUM('DWH Fact Table'[Revenue]), 'Date Working Table'[Year] = 2025, 'Date Working Table'[Month] = "February", 'Date Working Table'[Date] <= CurrentDate ) VAR Operating_Days_Feb_2025_MTD = CALCULATE( COUNTROWS('Date Working Table'), 'Date Working Table'[Year] = 2025, 'Date Working Table'[Month] = "February", 'Date Working Table'[Date] <= CurrentDate, 'Date Working Table'[IsWorkingDay] = TRUE() ) VAR Total_Operating_Days_Feb_2025 = CALCULATE( SUM('Date Working Table'[This Year DE Op Days]), 'Date Working Table'[Year] = 2025, 'Date Working Table'[Month] = "February" ) RETURN DIVIDE(Revenue_Feb_2025_MTD, Operating_Days_Feb_2025_MTD) * Total_Operating_Days_Feb_2025If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - 1 year ago
Hi ,
unfortunately we dont have date in DWH_ADJ fact table and think it will be a problem
Measure 1: DWH Revenue per Operating Day (Feb 2024)
DWH_Revenue_Per_Op_Day_Feb_24 =
VAR Revenue_Feb_24 = CALCULATE( SUM(DWH_Fact[Revenue]), 'Date_Working'[Year] = 2024, 'Date_Working'[Month] = "February")
VAR Operating_Days_Feb_24 = LOOKUPVALUE('Date_Working'[DE Op Days], 'Date_Working'[Year], 2024, 'Date_Working'[Month], "February")
RETURN
IF(Operating_Days_Feb_24 <> 0, Revenue_Feb_24 / Operating_Days_Feb_24, BLANK())Measure 2: DWH Revenue per Adjusted Operating Day (Feb 2025 MTD)
DWH_Revenue_Per_Adj_Op_Day_Feb_25 =
VAR CurrentDate = MAX(DWH_Fact[Date])
VAR Revenue_Feb_25_MTD = CALCULATE(
SUM(DWH_Fact[Revenue]),
'Date_Working'[Year] = 2025,
'Date_Working'[Month] = "February",
DWH_Fact[Date] <= CurrentDate
)
VAR Op_Days_Until_Today =
CALCULATE(
COUNTROWS('Date_Working'),
'Date_Working'[Year] = 2025,
'Date_Working'[Month] = "February",
'Date_Working'[Date] <= CurrentDate,
NOT(WEEKDAY('Date_Working'[Date],2) IN {6,7})
)
VAR Total_Op_Days_Feb_25 = LOOKUPVALUE('Date_Working'[DE Op Days], 'Date_Working'[Year], 2025, 'Date_Working'[Month], "February")
VAR AdjustedRevenue = (Revenue_Feb_25_MTD / Op_Days_Until_Today) * Total_Op_Days_Feb_25
RETURN
IF(Op_Days_Until_Today <> 0, AdjustedRevenue, BLANK())
- bhaskarpbi9991 year ago
Helper V
Hi Power Sir,
Thanks for the DAX formulas and Kudos for your great support.
We need the DAX formula logic which should work for current month dynamically when we select month from filter.
so let's say now feb'25, we want to calculate the first week revenue of Feb 25,the way we will calculate that isFirst Measure - Feb24 revenue/operating days of feb 24 (it shoudl calculate for previous year same month based on filter selection)
Second Measure - for 2025 first week would be Week1 feb 25 revenue/5 days (Operaitng days excluding saturday and sunday)
We are using month filter from MonthCal table and condition should be based on YearMth Key.
I aploligixe for not specifying the exact requirement during post creation.
Many thanks for your supprt.
Regards,
Bhaskar
- bhaskarpbi9991 year ago
Helper V
Hi ,
unfortunately we dont have date in DWH_ADJ fact table and think it will be a problem
- bhaskarpbi9991 year ago
Helper V
Hi,
Many thanks for your support and also for the solution.
Regards,
Bhaskar