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
b2wise
Helper III
Helper III

Pivot a Table Visual (DAX Measure Concept Help)

Hi all,

 

I find myself many times putting together a table visual in Power BI and then exporting it to Excel so I can pivot and find some more insights. Instead of exporting to excel I'd like to stay in Power BI and pivot right there, so to speak.

Example below.

Product CategorySales (measure)distinct products sold (measure)Avg sales price (measure)
dog food10001230
cat food20001725
fish food30065
dog toys50001715
aquarium parts10001217


This is a summary table of sales by product category, along with three measures. I'd like to group by  "distinct products sold" (evaluated by "Product Category") and sum sales that way. I cannot do that however because "distinct products sold" is a measure not a static field.

To do this, I export to excel so I can pivot and group by "distinct products sold" and the value is the Sum of "Sales".

How can I do this in Power BI? I think the answer is using CALCULATETABLE or SUMMARIZE but I don't know exactly how to go about it.

Thanks in advance!


1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file if it suits your requirement.

 

Jihwan_Kim_1-1708365721505.png

 

 

Jihwan_Kim_0-1708365701816.png

 

Sales measure: = 
SUM( Sales[Sales] )

 

distinct product sold: = 
COUNTROWS(SUMMARIZE(Sales, 'Calendar'[Date]))

 

expected result measure: = 
SUMX (
    FILTER (
        SUMMARIZE ( Sales, Category[Product Catetory] ),
        [distinct product sold:]
            = SELECTEDVALUE ( 'Product Sold distinct count CT'[Count] )
    ),
    [Sales measure:]
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
b2wise
Helper III
Helper III

You, sir, are a kind and generous genius! Thank you very much!

 

If you have patience, I have a couple more questions on the expected result measure:

 

  1. How do I add a filter using a measure such as average sales price > 30?
  2. I don't feel like my original problem is a very common one. What are other ways to solve the same problem? I'm thinking I could have created my table visual as a regular table in Power Query though it would be pretty difficult to calculate all those DAX measures.

    In short, you have answered my question and I am very grateful!

Thank you again

@Jihwan_Kim I forgot to @ you

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file if it suits your requirement.

 

Jihwan_Kim_1-1708365721505.png

 

 

Jihwan_Kim_0-1708365701816.png

 

Sales measure: = 
SUM( Sales[Sales] )

 

distinct product sold: = 
COUNTROWS(SUMMARIZE(Sales, 'Calendar'[Date]))

 

expected result measure: = 
SUMX (
    FILTER (
        SUMMARIZE ( Sales, Category[Product Catetory] ),
        [distinct product sold:]
            = SELECTEDVALUE ( 'Product Sold distinct count CT'[Count] )
    ),
    [Sales measure:]
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.