The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have had help to create the below DAX function -
However I have run into a problem when I went to use it in my actual data where I want to apply a date filter to see the values by each month, I hadnt included the dates in my sample data, would I need to write something into the calculation to have it calculating by the date as at the minute it gets the total of scrap by process correct for the year to date but when you split it out by the months the values by the date are not correct.
Hi Belle2015,
I guess, you have to expant you ALLEXEPT with the Date. But here ist a very good article about this topic.
Using ALLEXCEPT versus ALL and VALUES - SQLBI
KR
Clemens
Hi @Belle2015
You need to try modifying your DAX formula to respect the date context.
Allocated Scrap = VAR CurrentProcess = 'Work Order Value'[Process] VAR MachineWork = 'Work Order Value'[Work Value] VAR TotalProcessWork = CALCULATE( SUM('Work Order Value'[Work Value]), ALLEXCEPT('Work Order Value', 'Work Order Value'[Process], 'Date'[Date]) // Include date table in context ) VAR MachineCount = CALCULATE( DISTINCTCOUNT('Work Order Value'[Machine]), ALLEXCEPT('Work Order Value', 'Work Order Value'[Process], 'Date'[Date]) // Include date table in context ) VAR TotalScrap = CALCULATE( SUM('Scrap'[Value Scrapped]), ALLEXCEPT('Scrap', 'Scrap'[Process], 'Date'[Date]) // Include date table in context ) RETURN IF( TotalProcessWork > , TotalScrap * (MachineWork / TotalProcessWork), TotalScrap / MachineCount )
If you don't have a date table, you could use the month columns directly (though a date table is recommended)
Allocated Scrap = VAR CurrentProcess = 'Work Order Value'[Process] VAR CurrentMonth = SELECTEDVALUE('Work Order Value'[Month]) // Or your month column VAR MachineWork = 'Work Order Value'[Work Value] VAR TotalProcessWork = CALCULATE( SUM('Work Order Value'[Work Value]), ALLEXCEPT('Work Order Value', 'Work Order Value'[Process], 'Work Order Value'[Month]), 'Work Order Value'[Month] = CurrentMonth ) // Similar modifications for other variables
Hi @Elena_Kalina,
Thanks for the help.
I have tried the above with my calendar table but it then doesnt give any value for the scrap in my table?
It may have something to do with the ALLEXCEPT function in your measure. Try adding your date within this function, as this function removes other filters.
Please let me know if this works?
Did you make sure you have the right date columns from your scrap and work order value tables? Or a relation between?
HI @bnjmnnl ,
I have a relationship between the calendar and the scrap and the calendar and the work order value and I used the calendar in the DAX formula
Hi, Maybe it has something to do with the ALLEXCEPT function, as this removes all other filters. Try adding date here.
Maybe this will work?
User | Count |
---|---|
81 | |
74 | |
42 | |
30 | |
28 |
User | Count |
---|---|
108 | |
96 | |
53 | |
48 | |
47 |