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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply

Issue in SWITCH function

i everyone, I need help with a formula:

I have this table (Jerarquia de medidas)

Level 1Level 2
TON 
GSV 
OFFTactic
OFFManual
OFFTax

 

And I have in my data base, a formula for each measure: a formula for OFF, TON, GSV, Tactic, Manual and Tax.

So I need a formula that brings for each level,  the correct formula.

I have this:

Formula = 
VAR KpiList2 = SELECTEDVALUE('Jerarquia Medidas'[Level 2])
VAR KpiList1 = SELECTEDVALUE('Jerarquia Medidas'[Level 1])
RETURN
SWITCH(
    KpiList1;
    "TON"; [TON];
    "GSV"; [GSV Factura];
"OFF"; [OFF]; SWITCH( KpiList2; "Manual"; [Manual]; "Tactic"; [TACTICO]; "Tax"; [Tax] ) )

 The formula works for all the measures except If I add the line OFF to the formula. When I add OFF, I only see the total number of OFF for the measure OFF and for the measures Manual, Tactic and Tax.

What I need to see is for OFF the total number and for Manual, Tactic and Tax the subtotals.

 

Any ideas how I can solve this?

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@MariaFlorenciaB - Try this - it changes the order of the switches, so that if there is a single value for level 2, it will show that value, otherwise, it will show the level 1 value:

Formula =
VAR KpiList2 =
    SELECTEDVALUE ( 'Jerarquia Medidas'[Level 2] )
VAR KpiList1 =
    SELECTEDVALUE ( 'Jerarquia Medidas'[Level 1] )
RETURN
    SWITCH (
        KpiList2;
        "Manual"; [Manual];
        "Tactic"; [TACTICO];
        "Tax"; [Tax];
        SWITCH ( KpiList1; "TON"; [TON]; "GSV"; [GSV Factura]; "OFF"; [OFF] )
    )

Cheers!

Nathan

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@MariaFlorenciaB - Try this - it changes the order of the switches, so that if there is a single value for level 2, it will show that value, otherwise, it will show the level 1 value:

Formula =
VAR KpiList2 =
    SELECTEDVALUE ( 'Jerarquia Medidas'[Level 2] )
VAR KpiList1 =
    SELECTEDVALUE ( 'Jerarquia Medidas'[Level 1] )
RETURN
    SWITCH (
        KpiList2;
        "Manual"; [Manual];
        "Tactic"; [TACTICO];
        "Tax"; [Tax];
        SWITCH ( KpiList1; "TON"; [TON]; "GSV"; [GSV Factura]; "OFF"; [OFF] )
    )

Cheers!

Nathan

Thanks very much @Anonymous  !!!!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors