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
giangtongle
Frequent Visitor

Incorrect Grand total?

Hi, 

 

I know this is somehow a common question. I found some anwsers and tried with my dataset but not successed. Please help. I have table as below with Item code, Item name and its price. The data set has multiple-duplicated records. I wanted to create a measure that will calcuate price/item and show total of price of all items as Grand total. Measure = Sum(Price)/CountRows(Table). I got correct price/item, but not Grand  total. Please help. Thanks.

 

#       Item         Price

1A2,500,000
2B8,711,557
3C8,757,010
4D4,650,000
5E14,200,000
6F16,500,000
1A2,500,000
2B8,711,557
3C8,757,010
4D4,650,000
5E14,200,000
4D4,650,000
5E14,200,000
6F16,500,000
1A2,500,000
2B8,711,557
3C8,757,010

 

giangtongle_0-1660038452394.png

(The grand total should be a sum of all price/item: $55,318,567)

2 ACCEPTED SOLUTIONS
CNENFRNL
Community Champion
Community Champion

= SUMX(VALUES('TABLE'[Item]),CALCULATE(SUM('TABLE'[Price])/COUNTROWS('TABLE')))

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

SpartaBI
Community Champion
Community Champion

4 REPLIES 4
giangtongle
Frequent Visitor

BIG Thanks @CNENFRNL , @Smalfly, and @SpartaBI

 

Both options with SUMX function works well. I have another question: When I tried with my dataset by using the following syntax, I got a wrong Grand total. Any ideas? Thanks in advance.

 

ItemCost_Var =
VAR TotalCost =
    SUM('Table'[Price])
VAR NoOfRecords =
    COUNTROWS('Table')
RETURN
SUMX(
    VALUES('Table'[#]),
TotalCost/NoOfRecords)
 
giangtongle_0-1660055028966.png

 

Smalfly
Resolver III
Resolver III

Hi @giangtongle ,

 

your grand total is also calculated according to the formula Sum(Price)/CountRows(Table).

Please have a look at this post on ways for handling with totals for a measure.

SpartaBI
Community Champion
Community Champion

@giangtongle 
Here is a link to download a sample solution file:
Incorrect Grand total 2022-08-09.pbix




2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Showcase Report – Contoso By SpartaBI

Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

CNENFRNL
Community Champion
Community Champion

= SUMX(VALUES('TABLE'[Item]),CALCULATE(SUM('TABLE'[Price])/COUNTROWS('TABLE')))

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

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.