Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

Categorise sales volumes and number of products that fall into those categories

Hi everyone,

 

I am trying to solve the following:

 

I have a DimProduct table and a FctSales tabe.

 

I want to categorise sales so that I can then count the number of products that fits into each category of sales:

Example of the desired output:

SalesCategoryNumber of procucts

% of total
123,16946.67%
23,5087.07%
320,25540.8%
41,4032.83%
52290.46%
6-99901.99%
10+850.17%
Total49,639 

 

I have attempted to solve this by doing the following:

 

SalesCategory = 
VAR NoPreviousSales = CALCULATE(COUNT('FctSales'[SalesID]),'FctSales'[PreviousSalesID]=0)
return
VAR category = IF (
    NoPreviousSales = 1,
    "1",
    IF (
        NoPreviousSales = 2,
        "2",
        IF (
            NoPreviousSales = 3,
            "3",
            IF (
                NoPreviousSales = 4,
                "4",
                IF (
                    NoPreviousSales = 5,
                    "5",
                    IF (
                        NoPreviousSales > 5
                            && NoPreviousSales < 10,
                        "6-9",
                        IF ( NoPreviousSales > 9, "10+", "0" )
                    )
                )
            )
        )
    )
)
return SalesCategory

 

 

If I add this to a table then I get  the table which is fine

SalesCategory
1
2
3
4
5
6-9
10+

 

When I go and add the count('DimProduct'[ProductID]) to the table visual 

I dont get the expected values as in my above expected output instead I get the following:

 

SalesCategoryCount of ProductID
6-949,639
549,639
349,639
249,639
149,639
049,639

 

I have no idea why this is happening... 

1 ACCEPTED SOLUTION
johncolley
Solution Sage
Solution Sage

Does changing the Cross filter direction to Both fix this issue? If not, please provide some sample data. 

View solution in original post

6 REPLIES 6
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

Could you tell me if your problem has been solved by using @johncolley 's method? If it is, kindly Accept it as the solution. More people will benefit from it. Or if you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

Refer to:

How to Get Your Question Answered Quickly - Microsoft Power BI Community

How to provide sample data in the Power BI Forum - Microsoft Power BI Community

 

 

Best Regards,
Eyelyn Qin

johncolley
Solution Sage
Solution Sage

Does changing the Cross filter direction to Both fix this issue? If not, please provide some sample data. 

Anonymous
Not applicable

Hey @johncolley I have just applied that setting and it works! Thank you, BTW do you have any suggestions as to how I can achieve the percentages column? 

Hi @Anonymous ,

The following measure works on my limited example:

Sales % = 

Var categorycount = COUNT(Sales[ProductID])

Var overallcount = CALCULATE(COUNT(Sales[ProductID]), REMOVEFILTERS(Sales))

Var result = categorycount/overallcount

return

result

I've formatted Sales% as a % and changed decimal to 2 in my example below.

johncolley_0-1653283928844.png

 

 

 

 

johncolley
Solution Sage
Solution Sage

Hi @Anonymous,

 

You see that repition of the total number when there is no relationship or a relationship not filtering in the required direction between your two tables. Please review the relationship settings - or share details of it if you require further assistance.

 

Anonymous
Not applicable

Hi @johncolley 

 

Between my FctSales table I have a relationship on ProductKey that is Many-to-one on my DimProduct table. Cross filter direction: Single

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.