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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Maltaparis
Frequent Visitor

Dax measure to create a new dimension in my model

Hello everyone,

I'm reaching out to ask for your assistance in creating a DAX measure

In my data modl below, I would like a DAX measure that basically recreates the dimension Item in my data model, but categorizying it with the following rule :

  • If only item "A" is sold for a unique ID client, then the measure should display "A"
  • If only item "B" is sold for a unique ID client, then the measure should display "B"
  • If both items "A" and "B" are sold, then show "Mixed".

Thus, it will allows me to analyze my data with this new category. I cant add a static new calulated column because I want my measure to be sensitive to the time slicer.

 

Client ID

Date

Item

Quantity

Price 

Amount

1

08/12/2024

A

1

10

10

2

08/12/2024

A

2

10

20

2

08/12/2024

B

4

20

80

3

08/12/2024

A

3

10

30

4

08/12/2024

B

1

20

20

4

08/12/2024

B

2

20

40

5

08/12/2024

A

4

10

40

6

08/12/2024

B

6

20

120

 

With this, I should be able to generate a PivotTable that would display, for example, 6 unique clients with 2 classified as "Mixed", 3 as "A", and 1 as "B". I would also like to associate the numeric columns (Amount and Quantity) with this new classification.

I’ve tried to implement this, but I’m having difficulty. Below is my current approach. If anyone could help, I’d really appreciate it.

Also, I woul like , to add  the lastyearview (to identify for instance who was only A or B and now is Mixte)

 

 

Thank you in advance for your strong support!

 

 

VAR ClientArticles =
    CALCULATETABLE (
        VALUES ( 'Table'[Item] ),
        ALLEXCEPT ( 'Table', 'Table'[Client id] )
    )
RETURN
    SWITCH (
        TRUE (),
        COUNTROWS ( ClientArticles ) > 1, "Mixte",
        COUNTROWS ( ClientArticles ) = 1
            && MAX ( 'Table'[Item] ) = "A", "A",
        COUNTROWS ( ClientArticles ) = 1
            && MAX ( 'Table'[Item] ) = "B", "B",
        "Autre"
    )

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi, @Maltaparis 

 

You can try the following methods.

Measure = 
Var _count=CALCULATE(DISTINCTCOUNT('Table'[Item]),ALLEXCEPT('Table','Table'[Client ID]))
RETURN
SWITCH(TRUE(),
MAX('Table'[Item])="A"&&_count=1,"A",
MAX('Table'[Item])="B"&&_count=1,"B",
"Mixed")

vzhangtinmsft_0-1723601723579.png

Create a new calculation table.

Table 2 = SUMMARIZE('Table','Table'[Client ID],"Type",[Measure])

vzhangtinmsft_1-1723601768400.pngvzhangtinmsft_2-1723601782720.png

Is this the result you expected?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Maltaparis
Frequent Visitor

Yes it's what I am looking for!

Alsow I will.add a lastyearsameperiod function to analyse vs lastyear.

Thank you all for yout help

View solution in original post

4 REPLIES 4
Maltaparis
Frequent Visitor

Yes it's what I am looking for!

Alsow I will.add a lastyearsameperiod function to analyse vs lastyear.

Thank you all for yout help

Rupak_bi
Solution Sage
Solution Sage

Hi,

Please see below approach. If this solves your purpose, please accept as solution.

Rupak_bi_0-1723550242686.png

 

 

 



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

Hi Rupas, 

Thank you for your help, but I would like not to display all the customers id (there are thousands in the dataset)

When I do not show explicitly the id then the pivottable considers everything to be "Mixed"

Let say,  I expected my pivot table to look like that 

Thanks again for your help

ItemNumber of customers
A3
B2
Mixed1
Anonymous
Not applicable

Hi, @Maltaparis 

 

You can try the following methods.

Measure = 
Var _count=CALCULATE(DISTINCTCOUNT('Table'[Item]),ALLEXCEPT('Table','Table'[Client ID]))
RETURN
SWITCH(TRUE(),
MAX('Table'[Item])="A"&&_count=1,"A",
MAX('Table'[Item])="B"&&_count=1,"B",
"Mixed")

vzhangtinmsft_0-1723601723579.png

Create a new calculation table.

Table 2 = SUMMARIZE('Table','Table'[Client ID],"Type",[Measure])

vzhangtinmsft_1-1723601768400.pngvzhangtinmsft_2-1723601782720.png

Is this the result you expected?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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