cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
adicarmeliEX_
Regular Visitor

Return a Table With a SWITCH

hi,

I have the following table: "COSTORCOUNT"

adicarmeliEX__3-1685866808271.png

and a parameter table:  "parameterTable"

adicarmeliEX__4-1685867454865.png

 

I'm tring to return a table according to selectedvalue from the "parameterTable"

I put the paramter column in a slicer.

when selecting 0 -the excepted resuelt is the following table:

adicarmeliEX__1-1685866726111.png

 

and when selecting 1 -

adicarmeliEX__2-1685866759751.png

 

 

Below is the code:

 

 

dynamicSlicer = 
VAR _TableAdi = SUMMARIZECOLUMNS(COSTORCOUNT[Flag])
VAR _TableTamir = SUMMARIZECOLUMNS(COSTORCOUNT[Flag],FILTER(COSTORCOUNT,COSTORCOUNT[Flag]=0))

VAR _Switch = IF( SELECTEDVALUE(parameterTable[parameter]) = 1,
                         _TableAdi, _TableTamir)

return _Switch

 

 

 

I'm getting the following error: 

adicarmeliEX__0-1685866449826.png

The expression specified in the query is not a valid table expression.

 

 

any advice will be appreciated.

 

Thank you, Adi

@Tamiri  @tamiribas 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@adicarmeliEX_ I've never had any luck with DAX being able to return one table or another table. It doesn't like it. Try this instead:

dynamicSlicer = 
    VAR _Selected = SELECTEDVALUE(parameterTable[parameter])
    VAR _Table = SUMMARIZE(FILTER(COSTORCOUNT, [Flag] = _Selected),[Flag])
RETURN
    _Table

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

@adicarmeliEX_ I've never had any luck with DAX being able to return one table or another table. It doesn't like it. Try this instead:

dynamicSlicer = 
    VAR _Selected = SELECTEDVALUE(parameterTable[parameter])
    VAR _Table = SUMMARIZE(FILTER(COSTORCOUNT, [Flag] = _Selected),[Flag])
RETURN
    _Table

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors