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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

DAx to Create a dynamic Dimension Classification based on another dimension

Right heres my issue: I have 1 fact table on purchases, 2 dimensions (Products, Customers) 

 

I want to create a customer type depending on the majority purchased product for a given date range. 

 

Example: 

 

Division Dimension 
Fruit 
Meat 
Veg 

 

Date CustomerProduct Division Tons 
01/01/2018John Fruit 7
02/01/2018John Veg 8
03/01/2018Meg Fruit 13
04/01/2018Meg Meat 16
05/01/2018Meg Veg 5
03/01/2018SallyFruit 3
04/01/2018SallyMeat 2
05/01/2018SallyVeg 5

 

taking the maxium tonnage for that customer I want to asign a customer type to the customer Dimension (Example: 

 

Custom Dimension Customer Type 
John Veg 
Meg Meat
Sally Fruit

 

Any thoughts? 

 

Thanks 

 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous

From your example, it seems the “given date range” here is before 2018/5/1, so i use "date" column in a slicer and select "before 2018/5/1".

First i create a calendar date table

Table2 = CALENDARAUTO() 

please note not to create relationship between this date table with your table.

 

Then create measures in your table ( called Table1 below)

max = MAX(Table2[Date])

min = MIN(Table2[Date]) 

max purchase = CALCULATE(MAX(Table1[Tons ]),FILTER(ALLEXCEPT(Table1,Table1[Customer]),[Date ]>=[min]&&[Date ]<[max]))

max-produce = CALCULATE(MAX(Table1[Product Division ]),FILTER(ALLEXCEPT(Table1,Table1[Customer]),[Tons ]=[max purchase]))

9.png

 

 

Best Regards

Maggie

View solution in original post

4 REPLIES 4
v-juanli-msft
Community Support
Community Support

Hi @Anonymous

From your example, it seems the “given date range” here is before 2018/5/1, so i use "date" column in a slicer and select "before 2018/5/1".

First i create a calendar date table

Table2 = CALENDARAUTO() 

please note not to create relationship between this date table with your table.

 

Then create measures in your table ( called Table1 below)

max = MAX(Table2[Date])

min = MIN(Table2[Date]) 

max purchase = CALCULATE(MAX(Table1[Tons ]),FILTER(ALLEXCEPT(Table1,Table1[Customer]),[Date ]>=[min]&&[Date ]<[max]))

max-produce = CALCULATE(MAX(Table1[Product Division ]),FILTER(ALLEXCEPT(Table1,Table1[Customer]),[Tons ]=[max purchase]))

9.png

 

 

Best Regards

Maggie

Anonymous
Not applicable

HI- 

I'm getting an Error on Max Purchase 

A single value for column 'Date' in table 'Calendar 1' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

Can you assist? 

Hi @Anonymous

this error occurs for you put directly a column in a measure, but by design, you need to specify an aggregation such as min, max, count, or sum to get a single result.

Measure1=calendar[date] (error)

Measure2=max(calendar[date])

Do not worry you would get the max value for the [date] column, the formula of Measure2 only give the current value of each row. for example,

date           Measure2

2018/1/1    2018/1/1

2018/4/1    2018/4/1

2018/5/1    2018/5/1

 

to get the max value of the [date] column, you should define the filter content.

for example

date            Measure3

2018/1/1     2018/6/1

2018/2/1     2018/6/1

2018/3/1     2018/6/1

2018/4/1     2018/6/1

2018/5/1     2018/6/1

2018/6/1     2018/6/1

 

Measure3=calculate(max(calendar[date]),all(calendar))

 

Best Regards

Maggie

Greg_Deckler
Super User
Super User

Measure  = 
VAR __customer = MAX([Customer])
VAR __table = SUMMARIZE(ALL('table19'),[Customer],[Product Division ],"__Tons",SUM([Tons ]))
VAR __max = MAXX(FILTER(__table,[Customer]=__customer),[__Tons])
RETURN MAXX(FILTER(__table,[Customer]=__customer && [__Tons]=__max),[Product Division ])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.