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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Suhel_Ansari
Helper V
Helper V

Wrong Total in Table

Hi all, I am getting worng total, I am tryint to calcualte the price of Power BI Licsenes cost for PPU, PRO and Free users using the following table and dynamically calculate the total which I am getting wrong or null as total, please asssit. Thanks

Measure =
    VAR Total = CALCULATE( COUNT('Table'[EmailID]))
    VAR PPU =  IF(SELECTEDVALUE('Table'[License]) = "PBI_PREMIUM_PER_USER" , Total * 22.50 )
    VAR PRO =  IF(SELECTEDVALUE('Table'[License]) = "Power BI Pro" , Total * 13.10)
    VAR PFL =  IF(SELECTEDVALUE('Table'[License]) = "Free Users" , Total * 13.10 )
    VAR Result = SWITCH( TRUE() ,
        SELECTEDVALUE('Table'[License]) = "PPU" , Total * 22.5 ,
        SELECTEDVALUE('Table'[License]) = "PRO" , Total * 13.1 ,
        SELECTEDVALUE('Table'[License]) = "Free" , Total * 13.1 )
    RETURN
    IF( ISINSCOPE('Table'[License]) , Result , (PPU + PRO + PFL))
Suhel_Ansari_0-1766418089138.png

 

Data is very simple.

Suhel_Ansari_2-1766418129548.png

 

1 ACCEPTED SOLUTION

Hi @GeraldGEmerick  - I got the answer using the ADDCOLUMNS  however I have to use the multiple ADDCOLUMNS can you please help me to optimze this measure. Thanks 

Suhel_Ansari_3-1766466453283.png

 

View solution in original post

13 REPLIES 13
v-sgandrathi
Community Support
Community Support

Hi @Suhel_Ansari,

 

We wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.

If you need any further assistance, feel free to reach out.

 

Thank you for being a valued member of the Microsoft Fabric Community Forum!

v-sgandrathi
Community Support
Community Support

Hi @Suhel_Ansari,

Thank you @Royel @GeraldGEmerick @cengizhanarslan and @jgeddes for ypur response to the query.

Just wanted to follow up and confirm that everything has been going well on this. Please let me know if there’s anything from our end.
Please feel free to reach out Microsoft fabric community forum.

cengizhanarslan
Super User
Super User

Please try the following formula:

License Cost :=
VAR Lic   = SELECTEDVALUE ( 'Table'[License] )
VAR Users = DISTINCTCOUNT ( 'Table'[EmailID] )
VAR Price =
    SWITCH (
        Lic,
        "PBI_PREMIUM_PER_USER", 22.5,
        "Power BI Pro",         13.1,
        "Free Users",           0,
        0
    )
RETURN
IF (
    ISINSCOPE ( 'Table'[License] ),
    Users * Price,
    SUMX ( VALUES ( 'Table'[License] ), CALCULATE ( Users * Price ) )
)

 

 

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

hi @cengizhanarslan  - this meaure returns 0 as the output as seen in the following screen print. Thanks 

Suhel_Ansari_0-1766464672876.png

 

Seems like License values are not same as in the field useds in the visual and use use DISTINCTCOUNT insted COUNTA. If you used COUNTA to avoid nulls use DISTINCTCOUNTNOBLANK instead.

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.
Royel
Super User
Super User

Hi @Suhel_Ansari Since no sample file was shared, it’s difficult to write the exact DAX in one go. Please try the following and let me know how it goes.

License Cost = 
VAR CurrentCount = COUNT('Table'[EmailID])
VAR Multiplier = 
    SWITCH(
        SELECTEDVALUE('Table'[License]),
        "PBI_PREMIUM_PER_USER", 22.50,
        "Power BI Pro", 13.10,
        "Free Users", 13.10,
        BLANK()
    )
VAR RowResult = CurrentCount * Multiplier

// For Total row - iterate and calculate each license type
VAR TotalResult = 
    SUMX(
        VALUES('Table'[License]),
        VAR LicCount = CALCULATE(COUNT('Table'[EmailID]))
        VAR LicMultiplier = 
            SWITCH(
                'Table'[License],
                "PBI_PREMIUM_PER_USER", 22.50,
                "Power BI Pro", 13.10,
                "Free Users", 13.10,
                0
            )
        RETURN LicCount * LicMultiplier
    )

RETURN
IF(
    ISINSCOPE('Table'[License]),
    RowResult,
    TotalResult
)

 

Thanks 

 

Hi @Royel  - The meaure returns Blank and Zero as the Total result. Thanks

Suhel_Ansari_1-1766464866796.png

 

Ahh, in this case we need some work around, are you able to share some sample file with expected results. so that we can test and come with proper calculations for measure. 

jgeddes
Super User
Super User

Something like this approach may also work for you.

Measure = 
var _vTable = 
SUMMARIZE(
    'Table',
    'Table'[License],
    "__count", COUNT('Table'[License])
)
var _multiplier = 
SWITCH(
    SELECTEDVALUE('Table'[License]),
    "PPU", 22.5,
    "Pro", 13.1,
    "Free", 13.1,
    BLANK()
)
RETURN
SUMX(
    _vTable,
    [__count] * _multiplier
)

 

This creates a virtual table that summarzes the intial table by licence with the count of each license. The SWITCH _multiplier variable provides the correct multiplier for each licence type. 
The return statement sums the lines of the virtual table, multiplying the licence counts by the correct amount. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi @jgeddes - The measure retunrs total a blank. Thanks 

Suhel_Ansari_2-1766464970485.png

 

GeraldGEmerick
Super User
Super User

@Suhel_Ansari  So, when multiple rows are in scope like in the total row, the SELECTEDVALUE is going to return BLANK. You will need to use ADDCOLUMNS to add your calculation to a table variable and then use SUMX across that table for the total row.

Hi @GeraldGEmerick  - I got the answer using the ADDCOLUMNS  however I have to use the multiple ADDCOLUMNS can you please help me to optimze this measure. Thanks 

Suhel_Ansari_3-1766466453283.png

 

@Suhel_Ansari From what I can see, you can move the formulat for TOTAL into your Result variable. That way it isn't calculated unless it is necessary.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.