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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Switch function causing many rows

Hi all, 

 

I am using the following DAX measure to format the sum of sales & for some reason when I drop the measure in a visual a bunch of lines of data appear, any ideas on why that would happen/ how to fix it? Thanks!

 

Parent Annual Revenue =

var _1 = calculate(SUM('Sales Table'[Parent Annual Sales]))

var _2 = SWITCH (
TRUE (),
VALUE( _1) >= ( 10 ^ 8 ), FORMAT(_1, "$#,0,,,.## B; ($#,0,,,.## B)"),
VALUE( _1) >= ( 10 ^ 5 ), FORMAT(_1,"$#,0,,.## M; ($#,0,,.## M)"),
VALUE( _1) >= 1000, FORMAT(_1,"$#,0,.## K; ($#,0,.## K)"),
VALUE( _1) < 1000, "-"
)
return _1
1 ACCEPTED SOLUTION

Hmm. Does adding a blank check help at all?

 

Parent Annual Revenue =
VAR _1 =
    CALCULATE ( SUM ( 'Sales Table'[Parent Annual Sales] ) )
VAR _2 =
    SWITCH (
        TRUE (),
        ISBLANK ( _1 ), BLANK (),
        VALUE ( _1 ) >= ( 10 ^ 8 ), FORMAT ( _1, "$#,0,,,.## B; ($#,0,,,.## B)" ),
        VALUE ( _1 ) >= ( 10 ^ 5 ), FORMAT ( _1, "$#,0,,.## M; ($#,0,,.## M)" ),
        VALUE ( _1 ) >= 1000, FORMAT ( _1, "$#,0,.## K; ($#,0,.## K)" ),
        VALUE ( _1 ) < 1000, "-"
    )
RETURN
    _2

View solution in original post

7 REPLIES 7
AlexisOlson
Super User
Super User

Can you explain what you mean by "a bunch of lines of data appear"? What are you seeing and what do you expect to see?

Anonymous
Not applicable

when I add this measure to a table visual with anyother metric (lets say company name) I get a list of all the company names. I expect to see only one value for the filtered company name

Hmm. Does adding a blank check help at all?

 

Parent Annual Revenue =
VAR _1 =
    CALCULATE ( SUM ( 'Sales Table'[Parent Annual Sales] ) )
VAR _2 =
    SWITCH (
        TRUE (),
        ISBLANK ( _1 ), BLANK (),
        VALUE ( _1 ) >= ( 10 ^ 8 ), FORMAT ( _1, "$#,0,,,.## B; ($#,0,,,.## B)" ),
        VALUE ( _1 ) >= ( 10 ^ 5 ), FORMAT ( _1, "$#,0,,.## M; ($#,0,,.## M)" ),
        VALUE ( _1 ) >= 1000, FORMAT ( _1, "$#,0,.## K; ($#,0,.## K)" ),
        VALUE ( _1 ) < 1000, "-"
    )
RETURN
    _2

Hi,

 

I am having the same issue of multiple rows appearing when I apply the FORMAT function to conditionally format a specific row in a matrix visual as percentage. I tried adding the blank check but it didn't fix the issue for me. The issue does no occur if I remove the FORMAT function.

 

This is my DAX measure that returns the correct number of rows in the matrix. It blows up the number of rows once I change the line highlighted in red to 

VAR _percentDiscount =
FORMAT(DIVIDE(_subtotalFinancialAid,_subtotalTuitionRevenue),"Percent")
 
Selected Measure =
VAR _maxline =
MAX ('DWH Finance_Organization_Dim'[Line_Order] )

VAR _subtotalTuitionRevenue =
CALCULATE(SUM('ODS Net_Tuition'[Tuition_Billed])
, ALL('DWH Finance_Organization_Dim'[Title])
,'DWH Finance_Organization_Dim'[Line_Order] <= 3)
    
VAR _subtotalNetTuition =
CALCULATE(SUM('ODS Net_Tuition'[Tuition_Billed])
, ALL('DWH Finance_Organization_Dim'[Title])
,'DWH Finance_Organization_Dim'[Line_Order] <= 5)

VAR _subtotalFinancialAid =
CALCULATE(SUM('ODS Net_Tuition'[Tuition_Billed])
, ALL('DWH Finance_Organization_Dim')
,'DWH Finance_Organization_Dim'[Title] = "Financial Aid Awards")

VAR _percentDiscount =
DIVIDE(_subtotalFinancialAid,_subtotalTuitionRevenue)

VAR _subtotal =
SWITCH(TRUE(),

     _maxline = 3, _subtotalTuitionRevenue
     ,_maxline = 4, _subtotalFinancialAid*-1
        ,_maxline = 5, _subtotalTuitionRevenue - _subtotalFinancialAid
        ,_maxline = 6, _percentDiscount
        ,SUM('ODS Net_Tuition'[Tuition_Billed])
        )
RETURN _subtotal

Maybe try something like this:

Selected Measure =
VAR _maxline =
[...]
VAR _total = SUM ( 'ODS Net_Tuition'[Tuition_Billed] )
VAR _subtotal =
    SWITCH (
        TRUE (),
        _maxline = 3 && NOT ISBLANK ( _subtotalTuitionRevenue ),
			FORMAT ( _subtotalTuitionRevenue, "0.00" ),
        _maxline = 4 && NOT ISBLANK ( _subtotalFinancialAid ),
			FORMAT ( _subtotalFinancialAid * -1, "0.00" ),
        _maxline = 5 && NOT ISBLANK ( _subtotalTuitionRevenue - _subtotalFinancialAid ),
			FORMAT ( _subtotalTuitionRevenue - _subtotalFinancialAid, "0.00" ),
        _maxline = 6 && NOT ISBLANK ( _percentDiscount ),
			FORMAT ( _percentDiscount, "0.00%" ),
        NOT ISBLANK ( _total ),
			FORMAT ( _total, "0.00" )
    )
RETURN
    _subtotal

@AlexisOlson Thank you so much. That fixed my issue.

 

I added an alternate result to the DIVIDE function so that it returns 0 where the devisor was 0 otherwise those were being formatted as currency.

VAR _percentDiscount =
DIVIDE(_subtotalFinancialAid,_subtotalTuitionRevenue,0)
Anonymous
Not applicable

@AlexisOlson  that worked! thanks, good call on the blank

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors