Forum Discussion
special slicer?
Dears
I have a simple table with a Month column (stored as an integer) and a Value column. For example, 2401 represents January 2024, 2402 represents February 2024, and so on. The table contains around 14 rows, which Iโm displaying in a bar chart.
I want to add a slicer that lets the user choose how many months should be shown: 3, 6, or 12. Most tutorials demonstrate this using a standard date table, but my month field is just an integer code, not an actual date.
Do you have any suggestions on how to build a slicer in Power BI that controls how many integer-based โMonthโ entries appear in the chart?
tnx ๐
- Anonymous1 year ago
Hi Hugo999 , hello Idrissshatila, thank you for your prompt reply!
For your situation, please create an index column in table first, then create the measure as shown below:
FilterMeasure = VAR SelectedMonths = SELECTEDVALUE(PeriodSelection[NumMonths]) VAR MaxMonth =CALCULATE(MAX('Table'[Index]),ALLSELECTED('Table')) VAR MinMonth = MaxMonth - SelectedMonths + 1 RETURN IF(MAX('Table'[Index]) >= MinMonth && MAX('Table'[Index]) <= MaxMonth, 1, 0)Then filter the bar chart visual with measure=1:
Result for your reference:
Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
โโ
3 Replies
- IdrissshatilaSuper User
Hello Hugo999 ,
yes, you use the default slicer but use the type of the slicer from the formatting settings to list.
- Hugo999Frequent Visitor
hi
this does not take a custom amount of "months" into account. Very much assume, that some kind of "period selection" had to be set up, like:
PeriodSelection =DATATABLE ("PeriodLabel", STRING,"NumMonths", INTEGER,{{ "3 Monate", 3 },{ "6 Monate", 6 },{ "12 Monate", 12 }})then this needs to be a slicer somehow... this is the part, where i am stuck- AnonymousNot applicable
Hi Hugo999 , hello Idrissshatila, thank you for your prompt reply!
For your situation, please create an index column in table first, then create the measure as shown below:
FilterMeasure = VAR SelectedMonths = SELECTEDVALUE(PeriodSelection[NumMonths]) VAR MaxMonth =CALCULATE(MAX('Table'[Index]),ALLSELECTED('Table')) VAR MinMonth = MaxMonth - SelectedMonths + 1 RETURN IF(MAX('Table'[Index]) >= MinMonth && MAX('Table'[Index]) <= MaxMonth, 1, 0)Then filter the bar chart visual with measure=1:
Result for your reference:
Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
โโ