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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bsz412
Helper III
Helper III

how to print selected value as a fix number as calculated column

Hi,

 

I have a slicer where user can select one month from a dropdown list as start month.

 

 

bsz412_0-1647635853889.png

I would need to add the selected month number as a fixed value as a calculated column. 

this is my Start_month table, and in the "Selected" calculated column I would like to see 3 for each row

 

bsz412_1-1647635946118.png

how could I create that column?

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @bsz412 ,

 

I just created a table with Date column to test.

Eyelyn9_0-1647939215082.png

And we need to create three tables for three slicers with all Year/ all Months:

Eyelyn9_1-1647939474163.png

Then please create a flag measure, and apply it to visual-filter pane, set as "is 1"

Filter Flag = 
var _minDate=DATE(MIN('Year slicer'[Year]),MAX('Start Month'[Value]),1)
var _maxDate=DATE(MAX('Year slicer'[Year]),MAX('End Month'[Value])+1,1)
RETURN IF(MAX('Table'[Date]) >=_minDate && MAX('Table'[Date])<_maxDate,1,0)

 The original table will be filtered between 2020/7/1- 2021/2/28:

Eyelyn9_2-1647939597256.png

Best Regards,
Eyelyn Qin
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-eqin-msft
Community Support
Community Support

Hi @bsz412 ,

 

I just created a table with Date column to test.

Eyelyn9_0-1647939215082.png

And we need to create three tables for three slicers with all Year/ all Months:

Eyelyn9_1-1647939474163.png

Then please create a flag measure, and apply it to visual-filter pane, set as "is 1"

Filter Flag = 
var _minDate=DATE(MIN('Year slicer'[Year]),MAX('Start Month'[Value]),1)
var _maxDate=DATE(MAX('Year slicer'[Year]),MAX('End Month'[Value])+1,1)
RETURN IF(MAX('Table'[Date]) >=_minDate && MAX('Table'[Date])<_maxDate,1,0)

 The original table will be filtered between 2020/7/1- 2021/2/28:

Eyelyn9_2-1647939597256.png

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

@v-eqin-msft OMG, this is great, thank you so much!

tackytechtom
Super User
Super User

Hi @bsz412 ,

 

My initial thought was that this shouldn't be possible because the values in the calculated column are updated during a data refresh. This means any time your selection in the report would change, the value in the calculated column will not update. 

Here they discussed this issue:

Solved: Using Slicer values in a calculated column - Microsoft Power BI Community

 

And here another suggestion for a solution:

Power BI calculated column based on Slicer - deBUG.to

 

Does this help? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hi @tackytechtom,

Thanks for the clarification. The reason why I was trying this, is because I have to build a period slicer that looks like this

 

bsz412_0-1647642436350.png

They insist so hard, so building something else instead is unfortunately not an option. I was hoping that capturing the start year&month combo and end year&month in a measure can somehow help me filter the calendar table to the values that fall in between those 2 values. 

Right now I have no idea how will I create this format 😞

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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