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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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