March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
I'm new here and I hope you can help me.
I have a sales table like that:
Year | Company | Unit | Sales
2010 | CompA | UnitA | 100
2010 | CompA | UnitB | 200
2010 | CompB | UnitA | 500
2010 | CompB | UnitB | 200
2010 | CompB | UnitC | 300
2014 | CompA | UnitA | 600
...
So, for every company with different units you have Sales for different years.
I have a working measure that calculates the average sales (AVERAGEX) and depending on that I calculate three categories "Perfect" (>500), "OK (100-500)", "Bad (<100)" (SWITCH with using the AVERAGEX variable).
I need a second measure or more so that I can show data like that:
Year | Category | Percentage
2010 | Perfect | 20 %
2010 | OK | 80 %
2014 | Perfect | 5 %
2014 | OK | 75 %
2014 | Bad | 20 %
...
My problem are the categories, because they are not in my data model but calculated in the measures. How can I "connect" the three values to the sales tables?
Best regards
Michael
Solved! Go to Solution.
Hi @MichaelH78 ,
Hope all is going well.
Please follow these steps:
1.Create Category calculated columns based on different conditions.
Category = IF((Sales[Sales]) >= 500,"perfact",IF((Sales[Sales]) < 100,"bad","ok"))
2.Count rows based on different years.
AllRowsByYear = CALCULATE(COUNTROWS('Sales'), ALLEXCEPT('Sales', 'Sales'[Year]))
3.Create a table.
Table = SUMMARIZE (
Sales,
Sales[Year],
Sales[Category],
"RowCount", COUNTROWS(Sales),
"Percentage", DIVIDE (
COUNTROWS ( FILTER ( Sales, Sales[Year] = Sales[Year] && IF((Sales[Sales]) >= 500,"perfact",IF((Sales[Sales]) < 100,"bad","ok")) = Sales[Category] ) ),
[AllRowsByYear]
)
)
4.Drag the fields you need from the new table to the report page for display.
pbix file is attached.
Your needs should be solved at this point. If you have any questions, please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
hi @MichaelH78 ,
Please test it thoroughly. I am taking average of sales and then creating category. Is that the logic?
Step1 Create a calculated table, do not link it to any other table. This is just to hold all combination of Year and Category. Place Year and Category in table visual along with the measure.
You can see all the mockup data on the right side to validate the logic and results. PLease test with yours.
hi @MichaelH78 ,
Please test it thoroughly. I am taking average of sales and then creating category. Is that the logic?
Step1 Create a calculated table, do not link it to any other table. This is just to hold all combination of Year and Category. Place Year and Category in table visual along with the measure.
You can see all the mockup data on the right side to validate the logic and results. PLease test with yours.
... oh, great, thanks talespin. That's what I was looking for. And the realisation is ultimately much easier than I thought 😉 Thank you.
You're welcome.
Hi @MichaelH78 ,
Hope all is going well.
Please follow these steps:
1.Create Category calculated columns based on different conditions.
Category = IF((Sales[Sales]) >= 500,"perfact",IF((Sales[Sales]) < 100,"bad","ok"))
2.Count rows based on different years.
AllRowsByYear = CALCULATE(COUNTROWS('Sales'), ALLEXCEPT('Sales', 'Sales'[Year]))
3.Create a table.
Table = SUMMARIZE (
Sales,
Sales[Year],
Sales[Category],
"RowCount", COUNTROWS(Sales),
"Percentage", DIVIDE (
COUNTROWS ( FILTER ( Sales, Sales[Year] = Sales[Year] && IF((Sales[Sales]) >= 500,"perfact",IF((Sales[Sales]) < 100,"bad","ok")) = Sales[Category] ) ),
[AllRowsByYear]
)
)
4.Drag the fields you need from the new table to the report page for display.
pbix file is attached.
Your needs should be solved at this point. If you have any questions, please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
Hello Yang, thank you very much for your detailed help.
Unfortunately, I accepted your solution too early, because it does not work correctly yet 😉 When I insert a slicer, on Sales[Unit], nothing changes, which would be necessary. I still believe that the calculated column does not help, because the values should change depending on the selection of Unit.
I have inserted my current status in your Demo.pbix. The measure MyPercentage reacts correctly to the slicer and shows me the total number of category values (grouped by year, company and unit) for each year. Now I "only" need the number per different category value (Perfect, OK, Bad).
Best regards
Michael
Hi Mate
If this is what you meant follow the steps below:
1) Add a new column sales%
Sales% =
var A=
CALCULATE(sum(Sales[Sales]),ALLSELECTED(Sales[Company]))
VAR B=SUM(Sales[Sales])
RETURN
A/B
2) Add Category Column
Category =
if(Sales[Sales]>500,"Perfect",if(Sales[Sales]>=100 && Sales[Sales]<=500,"OK",IF(Sales[Sales]<100,"BAD")))
3) Calculate average sales with the measure
Average Sales = average(Sales[Sales])
Visualise the data Now
Hope it helped, Mark it correct if so !!
Rabi
Hello Rabi,
Thank you for your help. Unfortunately, this does not lead to success, which is mainly due to the fact that Sales% does not work as a calculated column, because the percentage value changes depending on the filter context. For example, if I filter on UnitB and UnitC, the result is different from UnitA, UnitB and UnitC.
My current status is as follows:
CatPerc =
VAR vAVG = AVERAGEX(Sales, Sales[Sales])
VAR vCat =
SWITCH(
TRUE(),
vAVG <= 100, "Bad",
vAVG > 100 && vAVG <= 500, "OK",
vAVG > 500, "Perfect"
)
VAR vTabFilterNoComp =
SUMMARIZE(
CALCULATETABLE( Sales, REMOVEFILTERS( Sales[Company] ) ),
Sales[Year],
Sales[Company],
"Cat", vCat
)
VAR vTabCatGroups =
SUMMARIZE(
vTabFilterNoComp ,
Sales[Year],
[Cat],
Sales[Company],
"Cnt", 1
)
VAR vCountAll = SUMX( vTabCatGroups , [Cnt] )
VAR vTabCat =
CROSSJOIN( VALUES( Years[Year] ), VALUES( Categories[Cat] ) )
--VAR vCountKat = SUMX( vTabCat , Categories[Cat] )
RETURN vCountAll
This is what I want:
But at the moment I only have the total values per year (i.e. 5 for 2010, 6 for 2014 and 3 for 2018).
I think my main problem is that the categories have no real relationship to the sales, right? I hope my problem is described reasonably comprehensibly 😉
Thanks in advance, Michael
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
18 | |
15 | |
9 | |
8 |
User | Count |
---|---|
37 | |
32 | |
18 | |
16 | |
13 |