Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I work at a waste management company and create statistics on weighing waste items in car scales.
I need to find the weight of household waste.
Therefore, industrial waste must be subtracted from mixed waste - for each item.
The measurement for an individual item is easy to find. Let's take a look at "Iron," which has ArticleNr "730" for mixed weighings, and "230" for industrial weighing. For this example, I will only focus on the total weight and not the YTD values.
Iron for the Home (Iron Home)
VAR Mixed Iron = CALCULATE ( SUM (Table[Weight]) ; Table[ArticleNr] - "730" )
VAR Industrial Iron = CALCULATE ( SUM (Table[Weight]) ; Table[ArticleNr] - "230" )
Return
Mixed Iron - Industrial Iron
Now, let's go one deeper (as DJ Hanzel says):
I need to find values for the year to date (YTD) and YTD last year (LY) for each household waste item.
I've managed to create measures for YTD and YTD LY, but only generic measures that only work on current rows within the data table.
That is, I can find out the numbers of waste items that are weighed - but not for household waste, you need to have a subtraction (mixture - industrial) to calculate the weight.
Mixed waste of industrial and household waste
ArticleNr | ArticleName | Weight YTD LY | Weight YTD |
730 | Iron | 500 | 300 |
751 | Paper | 550 | 450 |
766 | Plastics | 600 | 200 |
Industrial waste
ArticleNr | ArticleName | Weight YTD LY | Weight YTD |
230 | Iron | 250 | 100 |
251 | Paper | 50 | 40 |
266 | Plastics | 150 | 150 |
This is what I can show now, with two measures inside an array table.
I want to show household waste in a similar way.
The formulas I have used for my current measurements:
Solved! Go to Solution.
@AleksanderPunt Yes, that should work provided everything is in one source data table. Just use the [Article] column as row header and my suggested measure as your value. What that will do is sum all the industrial waste for that article for the selected time period, and sum all the mixed waste for that article for the selected time period and subtract them.
As for your Date slicer problem, try updating your Peso YTD LY measure to be something more like:
Peso YTD LY = CALCULATE([PesoYTD], DATEADD(DimDate[Date], -1, YEAR))
or similar.
Note for that to work you will need to create a DimDate table for your data model. Date tables are very important for getting accurate results in Time Intelligence (ie YTD) measures.
Once you have the DimDate table, you can use the Date from that table to filter for this year and the Peso YTD LY will still display for last year because we've used DATEADD to shift the selection of dates in the filter to last year's dates.
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
https://sites.google.com/site/allisonkennedycv
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
I agree with @v-easonf-msft , what does your raw data look like?
The Last Year measure is actually not needed if you just put the YTD weight in a table with Year in columns.
As for your question, measures are dynamic and follow the context of the report visualizations, so if you simply create a MEASURE:
Household Waste = [Mixed Waste]-[Industrial Waste]
that should do the trick.
When you put this measure in a visualization by material, then you'll have the right answer.
Your problem is that industrial iron has a different number to household iron, thus why I need to know what your raw data looks like (relationships view please) to be more helpful. If you have a nice data model though, you can pull the material labels from a DimMaterial table and the measures should talk to each other.
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
https://sites.google.com/site/allisonkennedycv
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Well, I can try to put togheter a sample-file with irrrelevant columns and articles trimmed - as well as limiting the time period.
All the data is in one datatable. Industrial waste doesn't have corresponding number-series as what to subtract from the mixed series. So I suppose the logic need to be entered in a manually entered table, where the column for article numbers is mapped to the original data table.
Will this work?
Column 1 - ArticleNr: Listing all article numbers
Column 2 - Article: Corresponding names across both mixed and industrial articles
Column 3 - Type: Labeling the article as Industrial, Mixed or Other
ArticleNr | Article | Type |
205 | Food | Industrial |
276 | Wood | Industrial |
705 | Food | Mixed |
So, if I'm using your measure as an example:
HH Waste = [Mixed Waste] - [Industrial Waste]
Will it be sufficient to have a common article name for industrial and mixed waste (like I did with Food in the table above), and setting this column (article") as the row header and your measure as value?
I tried your tip on just having YTD measure and putting year in columns.
This worked in a matrix, but lacks some benefits of a regular table.
1. In the regular table I inserted an article icon/logo, mapped through another datatable and collecting the images online. In the next column are the article names. In matrix it's only possible to have one dedicated row header column. Drill down is possible, but not something I wish for.
2. Percentage diff from year to year is not possible. It only displays weight per year.
3. The matrix takes into account the whole year, so I need to put in a filter for dates in order to limit the selection to a time period.
@AleksanderPunt Yes, that should work provided everything is in one source data table. Just use the [Article] column as row header and my suggested measure as your value. What that will do is sum all the industrial waste for that article for the selected time period, and sum all the mixed waste for that article for the selected time period and subtract them.
As for your Date slicer problem, try updating your Peso YTD LY measure to be something more like:
Peso YTD LY = CALCULATE([PesoYTD], DATEADD(DimDate[Date], -1, YEAR))
or similar.
Note for that to work you will need to create a DimDate table for your data model. Date tables are very important for getting accurate results in Time Intelligence (ie YTD) measures.
Once you have the DimDate table, you can use the Date from that table to filter for this year and the Peso YTD LY will still display for last year because we've used DATEADD to shift the selection of dates in the filter to last year's dates.
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
https://sites.google.com/site/allisonkennedycv
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
The eyeopener here was to map all codes as either "Mixed Waste" or "Industrial Waste", and then subtract the sum of "Industrial Waste" from the sum of "Mixed Waste" in a measure. Thanks a bunch, AllisonKennedy!!
I created a new table and manually entered all the article numbers in a column and labeled each row in multiple columns for future grouping-convenience. The main columns making the measure possible were ArticleNr, Article and Type. Afterwards I mapped the ArticleNr-column from this table to the main table ArticleNr-column.
Here's the final measure:
Hi , @AleksanderPunt
Are all the data " Mixed waste of industrial and household waste" and " Industrial waste" in the same table?
Can you share me some sample data /.pbix file to test ?
Best Regards,
Community Support Team _ Eason
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
95 | |
80 | |
68 | |
59 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |