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
Anonymous
Not applicable

Show sum in table column based on condition

Hello,

I have the following table in Power BI and i am using a slicer for the "Region" column.

  1. If i select Region = YUN, then the sum in the "Total" column is correct, since the currencies are the same, that is, USD.
  2. If i select Region = TOD, then the sum in the "Total" column is not correct, since it is adding up two different currencies.

The problem is that the sum shown at the end of the "Total" column is meaningless if the currencies are not the same in all the rows. I am trying to display the sum in the "Total" column only if the currencies are the same, otherwise hide the sum value. Is this possible? Any help is much appreciated!

 

Document IDRegionTotalCurrency
3998TOD6485.52NOK
4050TOD87889USD
4050WAP89367.5DKK
4060HEP27050.73EUR
4139YUN4785.25USD
4145WAP720DKK
4149HEP583EUR
4157WAP15204CAD
4160YUN4197USD
4160HEP44924EUR
4164WAP1297.59NOK

 

MakeItReal_1-1665316957480.png

MakeItReal_2-1665316998266.png

 

MakeItReal_3-1665317010013.png

 

 

3 ACCEPTED SOLUTIONS
PaulDBrown
Community Champion
Community Champion

Here is one way.

First the model:

model.pngInclude slicers from the dimension tables and use the dimension table fields in the visual. Next create this measure:

 

Filter Slicers = 
COUNTROWS(RELATEDTABLE(fTable))

 

Add this measure to the filter pane for each slicer and set the value to greater or equal to 1. This will filter each slicer to show the complementary values for each field only.

slicers.pngNow create the measure to show the total only when one currencies is displayed (if there are two or more currencias, the rows are displayed but not the total).

 

Filter Sum =
VAR _Rows =
    IF (
        ISBLANK ( [Sum Total] ),
        BLANK (),
        CALCULATE (
            DISTINCTCOUNT ( 'fTable'[Currency] ),
            ALLEXCEPT ( fTable, 'Region Table'[dRegion] )
        )
    ) //Calculates the distincount of currencies by region
RETURN
    IF (
        ISFILTERED ( 'Currency Tbale'[dCurrency] ),
        [Sum Total],
        //if a currency is selected, the sum is returned
        IF (
            _Rows > 1,
            IF ( ISINSCOPE ( 'Region Table'[dRegion] ), [Sum Total] ) // will not return a total if a currency is not selected and there are more than 1 currencies by region
            ,
            [Sum Total]
        )
    )
//will return the sum if a region is selected with only 1 currency.

 

and you will get:

curr.gif

 

 

Sample PBIX file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

For that you need this measure:

 

Sum converted to euros if =
VAR _Rows =
    IF (
        ISBLANK ( [Sum Total] ),
        BLANK (),
        CALCULATE (
            DISTINCTCOUNT ( 'fTable'[Currency] ),
            ALLEXCEPT ( fTable, 'Region Table'[dRegion] )
        )
    )
VAR _NumCurr =
    CALCULATE (
        DISTINCTCOUNT ( 'Currency Tbale'[dCurrency] ),
        ALLSELECTED ( 'Currency Tbale'[dCurrency] )
    )
RETURN
    IF ( _NumCurr = 1, [Sum Total], IF ( _Rows > 1, [Sum Euro], [Sum Total] ) )

 

conv.gif

(I've added an extra row with the region "Narnia" in USD to check the measure if more than one region is selected)

I have also altered the [Filter Sum] measure for the original table to account for the posibility of the selection of more than one currency:

 

 

 

Filter Sum =
VAR _Rows =
    IF (
        ISBLANK ( [Sum Total] ),
        BLANK (),
        CALCULATE (
            DISTINCTCOUNT ( 'fTable'[Currency] ),
            ALLEXCEPT ( fTable, 'Region Table'[dRegion] )
        )
    )
VAR _NumCurr =
    CALCULATE (
        DISTINCTCOUNT ( fTable[Currency] ),
        ALLSELECTED ( 'Currency Tbale'[dCurrency] )
    )
RETURN
    IF (
        AND ( NOT ( ISINSCOPE ( 'Region Table'[dRegion] ) ), _NumCurr <> 1 ),
        BLANK (),
        IF (
            ISFILTERED ( 'Currency Tbale'[dCurrency] ),
            [Sum Total],
            IF (
                _Rows > 1,
                IF ( ISINSCOPE ( 'Region Table'[dRegion] ), [Sum Total] ),
                [Sum Total]
            )
        )
    )

 

 

 

 

 

 

New file attached

(PS, if this works for you, please mark this post as the solution instead of the previous one, since this one covers the possibility of multiple currency selections for both the clustered column and table visuals!)





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

Ok. So thanks to the new requirements, I've come up with a much simpler solution to the measures needed:

Filter Sum =
VAR _Rows =
    CALCULATE (
        DISTINCTCOUNT ( fTable[Currency] ),
        ALLSELECTED ( 'Calendar'[Date] )
    )
RETURN
    IF ( _rows > 1, BLANK (), [Sum Total] )
Sum converted to euros if =
VAR _Rows =
    CALCULATE (
        DISTINCTCOUNT ( fTable[Currency] ),
        ALLSELECTED ( 'Calendar'[Date] ),
        ALLSELECTED ( fTable )
    )
RETURN
    IF ( _Rows = 1, [Sum Total], [Sum Euro] )

and consequently simplified all the other Conditional Formatting and title measures.

solution.gif

New file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

12 REPLIES 12
PaulDBrown
Community Champion
Community Champion

Here is one way.

First the model:

model.pngInclude slicers from the dimension tables and use the dimension table fields in the visual. Next create this measure:

 

Filter Slicers = 
COUNTROWS(RELATEDTABLE(fTable))

 

Add this measure to the filter pane for each slicer and set the value to greater or equal to 1. This will filter each slicer to show the complementary values for each field only.

slicers.pngNow create the measure to show the total only when one currencies is displayed (if there are two or more currencias, the rows are displayed but not the total).

 

Filter Sum =
VAR _Rows =
    IF (
        ISBLANK ( [Sum Total] ),
        BLANK (),
        CALCULATE (
            DISTINCTCOUNT ( 'fTable'[Currency] ),
            ALLEXCEPT ( fTable, 'Region Table'[dRegion] )
        )
    ) //Calculates the distincount of currencies by region
RETURN
    IF (
        ISFILTERED ( 'Currency Tbale'[dCurrency] ),
        [Sum Total],
        //if a currency is selected, the sum is returned
        IF (
            _Rows > 1,
            IF ( ISINSCOPE ( 'Region Table'[dRegion] ), [Sum Total] ) // will not return a total if a currency is not selected and there are more than 1 currencies by region
            ,
            [Sum Total]
        )
    )
//will return the sum if a region is selected with only 1 currency.

 

and you will get:

curr.gif

 

 

Sample PBIX file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi @PaulDBrown Thanks for your reply! I have a related question about presenting the same data in a chart, so that:

1. if the currencies do not match, then show the Y-axis as "Converted to EUR", else

2. if the currencies are the same, then show the Y-axis as the common currency.

Is this possible? Any help is much appreciated!

 

Document IDRegionTotalCurrencyConverted to EUR
3998TOD6485.52NOK621.58
4050TOD87889USD90233.88
4050WAP89367.5DKK12014.28
4060HEP27050.73EUR27050.73
4139YUN4785.25USD4912.92
4145WAP720DKK96.79
4149HEP583EUR583
4157WAP15204CAD11356.44
4160YUN4197USD4308.98
4160HEP44924EUR44924
4164WAP1297.59NOK124.36

 

MakeItReal_0-1665320936790.png

 

MakeItReal_1-1665321017313.png

 

For that you need this measure:

 

Sum converted to euros if =
VAR _Rows =
    IF (
        ISBLANK ( [Sum Total] ),
        BLANK (),
        CALCULATE (
            DISTINCTCOUNT ( 'fTable'[Currency] ),
            ALLEXCEPT ( fTable, 'Region Table'[dRegion] )
        )
    )
VAR _NumCurr =
    CALCULATE (
        DISTINCTCOUNT ( 'Currency Tbale'[dCurrency] ),
        ALLSELECTED ( 'Currency Tbale'[dCurrency] )
    )
RETURN
    IF ( _NumCurr = 1, [Sum Total], IF ( _Rows > 1, [Sum Euro], [Sum Total] ) )

 

conv.gif

(I've added an extra row with the region "Narnia" in USD to check the measure if more than one region is selected)

I have also altered the [Filter Sum] measure for the original table to account for the posibility of the selection of more than one currency:

 

 

 

Filter Sum =
VAR _Rows =
    IF (
        ISBLANK ( [Sum Total] ),
        BLANK (),
        CALCULATE (
            DISTINCTCOUNT ( 'fTable'[Currency] ),
            ALLEXCEPT ( fTable, 'Region Table'[dRegion] )
        )
    )
VAR _NumCurr =
    CALCULATE (
        DISTINCTCOUNT ( fTable[Currency] ),
        ALLSELECTED ( 'Currency Tbale'[dCurrency] )
    )
RETURN
    IF (
        AND ( NOT ( ISINSCOPE ( 'Region Table'[dRegion] ) ), _NumCurr <> 1 ),
        BLANK (),
        IF (
            ISFILTERED ( 'Currency Tbale'[dCurrency] ),
            [Sum Total],
            IF (
                _Rows > 1,
                IF ( ISINSCOPE ( 'Region Table'[dRegion] ), [Sum Total] ),
                [Sum Total]
            )
        )
    )

 

 

 

 

 

 

New file attached

(PS, if this works for you, please mark this post as the solution instead of the previous one, since this one covers the possibility of multiple currency selections for both the clustered column and table visuals!)





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

@PaulDBrown Thank you for another brilliant solution!

By the way, how did you create the animated gif? It is an excellent way to show a quick demo!

I use an app called "screen to gif" which is free to download.

BTW, I edited the file and the [Filter Sum] measure while you were posting, so please check the current measure and download the file as it's posted now!

And please change the solution status to the last post -it corrects errors if there is more than one selection in the slicers!)





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

@PaulDBrown Thanks for updating the solution! I am going through the code to try to understand it better. Could you please identify which of those measures are relevant? I would like to clean up a little so that it is a bit easier to figure out.

 

MakeItReal_0-1665425303709.png

From my understanding, the only measures which should be kept are:

  1. Filter Sum
  2. Sum Total
  3. Sum converted to euros if
  4. Title if euros

Is this correct?

MakeItReal_1-1665425333500.png

 

Yes, sorry about the extra measures. Let me shed some light:

measures with "CF" are for conditional formatting. If they contain the word "Title" (either with CF or without), they are used for conditional formatting the title text. Apart from these, you can get rid of "TEST"

(Filter Slicers is important to filter the other slicer based on selections)

Sum Euro is just the sum of the Euro field

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

@PaulDBrown Thanks for the clarifications!

I have added 2 columns to the table: City and Registered Date.

Document IDRegionCityRegistered DateTotalCurrencyEuro conversion
3998TODLondon01/07/20216485.52NOK621.58
4050TODLondon09/11/202187889USD90233.88
4050WAPSaint Petersburg11/12/202189367.5DKK12014.28
4060HEPSaint Petersburg13/12/202127050.73EUR27050.73
4139YUNMadrid05/01/20224785.25USD4912.92
4145WAPMadrid06/01/2022720DKK96.79
4149HEPMadrid27/02/2022583EUR583
4157WAPParis04/04/202215204CAD11356.44
4160YUNParis09/04/20224197USD4308.98
4160HEPMinsk06/05/202244924EUR44924
4164WAPMoscow07/06/20221297.59NOK124.36
5555NarniaRome09/09/20221234USD6666

 

I am trying to add slicers for Document ID, City and Registered Date. All 4 slicers work fine in the table. But the slicers (except for the Region slicer) do not give the correct results in the chart since the currencies are always converted to Euro, even when all the currencies listed are similar.

In the chart, i also grouped the data by Registered Date and used a Calendar table to show them by month-year.

 

The Region slicer is set and the chart below displays correctly.

MakeItReal_6-1665447448883.png

 

The Document ID slicer is set and the chart below should display: Currency in DKK.

MakeItReal_3-1665447204184.png

 

The City slicer is set and the chart below should display: Currency in USD.

MakeItReal_4-1665447266165.png

 

The Registered Date slicer is set and the chart below should display: Currency in USD.

MakeItReal_5-1665447313460.png

 

The model:

MakeItReal_1-1665446563231.png

 

Any idea what could be wrong and how to fix it?

 

Here is the modified PBIX file: https://drive.google.com/file/d/18wvj98K8xjtsdrRKYwQgNoCghOck2grn/view?usp=sharing

 

Ok. So thanks to the new requirements, I've come up with a much simpler solution to the measures needed:

Filter Sum =
VAR _Rows =
    CALCULATE (
        DISTINCTCOUNT ( fTable[Currency] ),
        ALLSELECTED ( 'Calendar'[Date] )
    )
RETURN
    IF ( _rows > 1, BLANK (), [Sum Total] )
Sum converted to euros if =
VAR _Rows =
    CALCULATE (
        DISTINCTCOUNT ( fTable[Currency] ),
        ALLSELECTED ( 'Calendar'[Date] ),
        ALLSELECTED ( fTable )
    )
RETURN
    IF ( _Rows = 1, [Sum Total], [Sum Euro] )

and consequently simplified all the other Conditional Formatting and title measures.

solution.gif

New file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

@PaulDBrown Thanks for the updated and simplified solution!

Maybe i'm wrong but it seems like the dimension tables are no longer needed?

MakeItReal_2-1665495227536.png

 

I have changed the selected Fields for the table and it does not seem to make any difference:

MakeItReal_0-1665494941436.png

 

MakeItReal_1-1665494976140.png

 

I have also updated the slicers (Region, City and Document ID) to use the Fields from the fTable.

MakeItReal_0-1665496387635.png

 

MakeItReal_1-1665496404458.png

 

But before i delete the dimension tables, i would appreciate your confirmation - just in case something goes wrong if more data is added in the table.

It is a best practice and very highly recommended to use dimension tables!

Personally I would not delete them, and use them as the fields for measures, filters, slicers etc...





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Dinesh_Suranga
Continued Contributor
Continued Contributor

@Anonymous 

Hi,

create a measure with SUMX to get the total.

thank you.

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors