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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
juanroblesoct9
Frequent Visitor

Query from Service Pack using SummarizeColumns and add a column with Switch (Case When in SQL)

Trying to get data using this query adding Switch function similar as case when using switch but not working.

 

EVALUATE
SUMMARIZECOLUMNS (

'Geo Hierarchy'[Country],
'Prod Hierarchy'[Product Lvl 1],
'Prod Hierarchy'[Product Lvl 2],
'Prod Hierarchy'[Product Lvl 3],

SWITCH('Prod Hierarchy'[Product Lvl 7],{"Play"},"Play",
{"Run"},"Run",
"Others"
),

 

FILTER (
VALUES ( 'Geo Hierarchy'[Country] ),
'Geo Hierarchy'[Country], IN { "Latam","US"}
),
"Total Revenue", [RevUSD]
)

4 REPLIES 4
juanroblesoct9
Frequent Visitor

Let me elaborate on the question, below will find an SQL and DAX intended view which is not working as the intent is to have less rows imported..

 

SQL

With PreTable as (

Select
'Geo Hierarchy'[Country],'Prod Hierarchy'[Prd Lvl 1],'Prod Hierarchy'[Prd Lvl 2],
case when 'Prod Hierarchy'[Prd Lvl 3] like '%crawl%' then 'crawl'
when 'Prod Hierarchy'[Prd Lvl 3] like '%walk%' then 'walk'
when 'Prod Hierarchy'[Prd Lvl 3] like '%run%' then 'run'
else 'Others'
end [NewLvl3],
SUM([TotalRev]) as [Rev]
from ServicePack
where 'Calendar'[Year]='2019'
Group by
'Geo Hierarchy'[Country],'Prod Hierarchy'[Prd Lvl 1],'Prod Hierarchy'[Prd Lvl 2],'Prod Hierarchy'[Prd Lvl 3]
)

Select
'Geo Hierarchy'[Country],'Prod Hierarchy'[Prd Lvl 1],'Prod Hierarchy'[Prd Lvl 2],[NewLvl3],SUM([Rev])[Rev]
from PreTable
Group by
'Geo Hierarchy'[Country],'Prod Hierarchy'[Prd Lvl 1],'Prod Hierarchy'[Prd Lvl 2],[NewLvl3]


DAX (not working)


EVALUATE
SUMMARIZECOLUMNS (
'Geo Hierarchy'[Country],'Prod Hierarchy'[Prd Lvl 1],'Prod Hierarchy'[Prd Lvl 2],
SWITCH(SELECTEDVALUES('Prod Hierarchy'[Prd Lvl 3]),
"crawl","crawl",
"run","run"
"Others"
),

FILTER (
VALUES ( 'Calendar'[Year]),
'Calendar'[Year] IN { "2019"}
),
"Rev", [TotalRev]
)

Anonymous
Not applicable

Hi @juanroblesoct9,

Can you please share some dummy data and table relationship mappings? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

For the switch parts, you can try like these:

        SWITCH (
            TRUE (),
            SEARCH ( "crawl", 'Prod Hierarchy'[Prd Lvl 3], 1, BLANK () ), "crawl",
            SEARCH ( "run", 'Prod Hierarchy'[Prd Lvl 3], 1, BLANK () ), "run",
            "Others"
        )

From SQL to DAX: String Comparison - SQLBI

Regards,

Xiaoxin Sheng

Greg_Deckler
Community Champion
Community Champion

@juanroblesoct9 Try:

SWITCH('Prod Hierarchy'[Product Lvl 7],"Play","Play",
"Run","Run",
"Others"
),

 

If a measure, you may have to use an aggregation around your column, if it is a column.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Is a column as want to replicate case when in SQL.

The sugestion is not working.

the error shown "A single value for column "Prod Lvl7" in table "Prod Hierarchy" cannot be determined.  This happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count...

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.