Forum Discussion
Need help with DAX Formula
- 9 months ago
Hi ahmer_malick ,
Thanks for the update and additional details.
Please try the below updated measure, which evaluates the last available Promise Date per Branch Plant and SKU within each month and returns the corresponding Quantity Available value:
Qty Available Last Actual Day In Month = VAR _SelEOM = MAX ( 'Calendar'[EOM] ) VAR _LastDateInMonth = CALCULATE ( MAX ( 'Sheet1'[Promise Date] ), ALLEXCEPT ( 'Sheet1', 'Sheet1'[Branch/ Plant], 'Sheet1'[Parent 2nd Item Number] ), 'Sheet1'[Promise Date] <= _SelEOM, 'Sheet1'[Promise Date] > EOMONTH ( _SelEOM, -1 ) ) RETURN CALCULATE ( SUM ( 'Sheet1'[Quantity Available] ), FILTER ( ALLEXCEPT ( 'Sheet1', 'Sheet1'[Branch/ Plant], 'Sheet1'[Parent 2nd Item Number] ), 'Sheet1'[Promise Date] = _LastDateInMonth ) )Please let us know if it gives the expected output for all SKUs across branches.
Thank you.
Hi,
Looking at your Measure and pictures, I dont see a Date table that's used to filter the fact table. It's always recommended to build a proper Date table and have it connected with your table, in your case the 'DEMAND & SUPPLY (3)'[Sched Pick] column in fact table with one-to-many relationship. This way your MAX(Date) would behave as expected.
With this all set up, replace your VAR LastDayOfMonth with
VAR LastDayOfMonth =
EOMONTH ( MAX ( 'Date'[Date] ), 0 )
I tried that but the problem to use this logic is that if the last date is 28 or 29th of the month and the EOD is 30 or 31st it ignores those
- v-veshwara-msft10 months agoCommunity Support
Hi ahmer_malick ,
Thanks for the clarification. This happens because the EOMONTH() function returns the calendar month-end date (30th or 31st), and if that date doesn’t exist in your data - for example, when the latest record for that month is on the 28th or 29th - the result appears blank.
The approach I shared earlier avoids this by using a “less than or equal to” comparison with the month-end date, so it still returns results for all available dates within each month.
Could you please try that version and confirm if it gives the expected output across months.
- v-veshwara-msft10 months agoCommunity Support
Hi ahmer_malick ,
Just wanted to check if the response provided was helpful. If further assistance is needed, please reach out.
Thank you.- ahmer_malick10 months agoHelper II
I would need more help. I added business calender as well but it didn't work. You can check the file as well