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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
briguin
Helper I
Helper I

Create a Dimesion Table from a Raw table - Description Based on most used Items

I have a simple raw table. I want to create a Product Dimension table from the Raw Source.

Each Location can overwrite the ProdDescription locally. In most cases, they will use a default name but there will be outliers. 
I want to use the Product Description that has the highest summed quantity.

 

I had thought of building 2 temporary tables from the raw

Table1 = Summarize RawData to ProductCode,ProductDescp,Sum(Qty)

Table2 = Summarize Table1 with a Rank and only show if Rank = 1

Then Relate Table2 back to RawData

 

I feel like that is going the long way. Is there a better Way?

 

Final Result Desired:

Product Description for each Product code that sums to have the highest Qty

 

briguin_0-1599702935062.png

 

***** Solution was accepted below but there was a final corrected piece of code:
Here was the final code I used

SummarizedTable3 = 
VAR __Table1 = Summarize(RawTable,[ProdCode],[ProdDescp],"Qty",Sum(RawTable[Qty]))
VAR __Table2 = ADDCOLUMNS(__Table1 ,"Rnk", RANKX(all(RawTable[ProdCode], RawTable[ProdDescp]),CALCULATE(SUM(RawTable[Qty]))))
RETURN
    filter(__Table2,[Rnk]=1)

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@briguin , Try like

filter(ADDCOLUMNS(Summarize(Table,[ProductCode],[ProductDescp],"Qty",Sum(Table[Qty])) ,"Rnk", RANKX(all(Table[ProductCode], Table[ProductDescp]),CALCULATE(COUNT(Table[Qty])))),[Rnk]=1)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@briguin , Try like

filter(ADDCOLUMNS(Summarize(Table,[ProductCode],[ProductDescp],"Qty",Sum(Table[Qty])) ,"Rnk", RANKX(all(Table[ProductCode], Table[ProductDescp]),CALCULATE(COUNT(Table[Qty])))),[Rnk]=1)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak 
I think that's close enough.

Made a couple of tweaks to your Code.
Broke it out to variables, so I could better understand

SummarizedTable3 = 
VAR __Table1 = Summarize(RawTable,[ProdCode],[ProdDescp],"Qty",Sum(RawTable[Qty]))
VAR __Table2 = ADDCOLUMNS(__Table1 ,"Rnk", RANKX(all(RawTable[ProdCode], RawTable[ProdDescp]),CALCULATE(SUM(RawTable[Qty]))))
RETURN
    filter(__Table2,[Rnk]=1)

 

Changed to Sum vs Count. Looks like correct results. Count returned a single row 

briguin_0-1599707200973.png

 

@briguin OK, admittedly, there were errors made: 🙂

 

Table (21a) = 
  VAR __Table = SUMMARIZE('Table (21)',[ProdCode],[ProdDescp],"Qty",SUM('Table (21)'[Qty]))
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "Max",COUNTROWS(FILTER(__Table,[Qty]<=EARLIER([Qty]) && [ProdCode]=EARLIER([ProdCode]) && [ProdDescp]=EARLIER([ProdDescp])))
    )
RETURN
  FILTER(__Table1,[Max]=1)

 

PBIX is attached.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@briguin  - Perhaps:

New Table =
  VAR __Table = SUMMARIZE('Table',[ProdCode],[ProdDescp],"Count",COUNT([Qty]))
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "Max",COUNTROWS(FILTER(__Table,[Max]<=EARLIER([Count])))
    )
RETURN
  FILTER(__Table,[Max]=1)


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 


I couldn't quite make the leap with your logic.

It looks like it's was leveraging a row count vs me wanting to do a summation

I was thinking __Table2 would be a rank but seems like I just need to flag the max somehow and filter.

 

New Table = 
  VAR __Table1 = SUMMARIZE('RawTable',[ProdCode],[ProdDescp],"TotQty",SUM(RawTable[Qty]))
  VAR __Table2 =  
RETURN
    __Table1

2020-09-09 21_41_32-Window.png

@briguin Flagging max was the part of the code you apparently didn't implement.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.