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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Gazsim44
Helper III
Helper III

Add Total to Column in ADDCOLUMNS Measure

Hi All, I have two measures created to show the Top 'N' and 'Others' in terms of highest profit but when added to my table neither column is able to produce a total for the column. Is it possible to add this in anyway?

 

The two measures are as per below;

Other = 
VAR TopNumber = 
    IF( HASONEVALUE('TopN Filter'[TopN]),VALUES('TopN Filter'[TopN]),10)
VAR Rest =
    DISTINCTCOUNT(Air[Parent Customer]) - TopNumber
RETURN
    IF(
        HASONEVALUE(CustomerName[Parent Customer]),
        IF(
            VALUES(CustomerName[Parent Customer]) = "Others",
            SUMX(
                TOPN(
                    Rest,
                    ADDCOLUMNS(
                        VALUES(Air[Parent Customer]),
                        "Measure",'Air Measures'[Total GP Air]
                    ),
                    [Measure],ASC
                ),
                [Measure]
            )
        )
    )
Top X = 
VAR TopNumber = 
    IF( HASONEVALUE('TopN Filter'[TopN]),VALUES('TopN Filter'[TopN]),10)
VAR Rest = 
    COUNTROWS (Air) - TopNumber
RETURN
    IF(
        HASONEVALUE(CustomerName[Parent Customer]),
        CALCULATE(
            [Total GP Air],
            FILTER(
                Air,
                Air[Parent Customer] = VALUES(CustomerName[Parent Customer])
                && CONTAINS(
                    TOPN(
                        TopNumber,
                        ADDCOLUMNS(
                            ALL(CustomerName[Parent Customer]),
                            "Gross Profit", CALCULATE(
                                [Total GP Air],
                                FILTER(Air,Air[Parent Customer] = EARLIER(CustomerName[Parent Customer]))
                            )
                        ),
                        [Gross Profit],DESC
                    ),
                    CustomerName[Parent Customer],VALUES(CustomerName[Parent Customer])
                ))))

 With the resulting table currently looking like this;

 
3 REPLIES 3
Greg_Deckler
Super User
Super User

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
AllisonKennedy
Super User
Super User

@Gazsim44  can you try uploading the photo of table again, I can't see it.

 

What is the data type for the two measures? I haven't spent much time reading your full post to know if that's the problem, but that's one of the first things I'd check. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedyBoth are set to whole number so I would hope this shouldnt be an issue?

 

Attached a copy of the table again.

 

Capture.PNG

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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