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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Delion
Helper IV
Helper IV

error : The expression refers to multiple columns. Multiple columns cannot be converted to a scalar

Delion_0-1613463334259.png

Hi

I want to achieve slicer for:

> last day

> last 30 day

> MTD

but I received this error : The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

but can't found any error in Dax

Any input will helpful

 

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @Delion ,

 

Try to create a new table like below:

Table 2 = 
var LastDay = TODAY()-1
var Last30D = TODAY()-30
var MTD_START = DATE(YEAR(TODAY()),1,1)
var t1 = ADDCOLUMNS(FILTER('Table','Table'[Date]=LastDay),"selection","LastDay")
var t2 = ADDCOLUMNS(FILTER('Table','Table'[Date]>=Last30D&&'Table'[Date]<=TODAY()),"selection","Last30D")
var t3 = ADDCOLUMNS(FILTER('Table','Table'[Date]>=MTD_START&&'Table'[Date]<=TODAY()),"selection","MTD")
return UNION(t1,t2,t3)

V-lianl-msft_0-1613726464802.png

Another way is to create measures for different periods of calculation, and then use slicers to display measures for different periods.https://www.fourmoo.com/2017/11/21/power-bi-using-a-slicer-to-show-different-measures/ 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
V-lianl-msft
Community Support
Community Support

Hi @Delion ,

 

Try to create a new table like below:

Table 2 = 
var LastDay = TODAY()-1
var Last30D = TODAY()-30
var MTD_START = DATE(YEAR(TODAY()),1,1)
var t1 = ADDCOLUMNS(FILTER('Table','Table'[Date]=LastDay),"selection","LastDay")
var t2 = ADDCOLUMNS(FILTER('Table','Table'[Date]>=Last30D&&'Table'[Date]<=TODAY()),"selection","Last30D")
var t3 = ADDCOLUMNS(FILTER('Table','Table'[Date]>=MTD_START&&'Table'[Date]<=TODAY()),"selection","MTD")
return UNION(t1,t2,t3)

V-lianl-msft_0-1613726464802.png

Another way is to create measures for different periods of calculation, and then use slicers to display measures for different periods.https://www.fourmoo.com/2017/11/21/power-bi-using-a-slicer-to-show-different-measures/ 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Delion , I doubt something is wrong at lastday and monthstart var

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

hi @amitchandak 

 

This is DAX I use

 

LastDay/Last30D/MTD Selection =
Var TodayDate = TODAY()
Var YearStart = CALCULATE(STARTOFYEAR(CL_Prod[Month Year]), YEAR(CL_Prod[Month Year]) = YEAR(TodayDate))
Var MonthStart = CALCULATE(STARTOFYEAR(CL_Prod[Month Year]), YEAR(CL_Prod[Month Year]) = YEAR(TodayDate), MONTH(CL_Prod[Month Year]) = MONTH(TodayDate))
Var Result =
UNION (
ADDCOLUMNS (
CALENDAR ( YearStart, TodayDate),
"Selection", "YTD"
),
ADDCOLUMNS (
CALENDAR ( MonthStart, TodayDate),
"Selection", "MTD"
)
)
RETURN
Result

 

 

==

Delion_0-1613492656896.png

 

This is what I want to achieve : create category MTD, YTD beside date

 

I'm following this tutorial

https://www.youtube.com/watch?v=AdLDYohLeJc

@amitchandak 

may I ask how to attach pbix  here ?

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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