Forum Discussion

NadeemAhamed's avatar
NadeemAhamed
Icon for Helper V rankHelper V
2 years ago
Solved

Passing Slicer value to column header name

Dear All,

 

Thank you in advance to all. 

 

I have month column (Apr,may...mar) and Previous and Current Month Data columns. 

 

 

I am trying to pass the slicer values to column header name

if i have selected Apr month in slicer then i want to pass that month name to the column header name such as current month data + Selected month (Apr) and previous month data + Previous month (Mar) from slicer.

 

i have attached the pbix file for your reference. 

 

pbix: https://toyotsu.box.com/s/52e2wnzt2xptn6ql7susxyianj23txqb

 

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi NadeemAhamed ,

    I think the first thing you need to know is that in Power BI Desktop's tables, you can't dynamically change the names of the columns you put in by means like DAX, you can only change its style and static name.

    So in your case, I think if you want to implement your needs, maybe you can try using Card Visual. The card is not in the form, but it can be returned in the form you want.

    Measure = "Current Month   " & SELECTEDVALUE(Sheet2[Month]) & "   Data"

     

     

     

    Best Regards

    Yilong Zhou

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

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi NadeemAhamed ,

    Firstly I create a new table.

    Table = 
    VAR _vtable =
        SUMMARIZE (
            ADDCOLUMNS (
                CALENDAR ( "2023-1-1", "2023-12-1" ),
                "_Month", FORMAT ( [Date], "MMM" ),
                "_monthNum", MONTH ( [Date] )
            ),
            [_Month],
            [_monthNum]
        )
    RETURN
        EXCEPT (
            _vtable,
            ADDCOLUMNS (
                SELECTCOLUMNS (
                    EXCEPT ( SELECTCOLUMNS ( _vtable, [_Month] ), VALUES ( Sheet2[Month] ) ),
                    "_mon", [_Month]
                ),
                "MN", MAXX ( FILTER ( _vtable, [_mon] = [_Month] ), [_monthNum] )
            )
        )

    Then I create a measure and here is the DAX code.

    Measure =
        VAR _currentMonth =
            SELECTEDVALUE ( Sheet2[Month] )
        VAR _currentMonthNum =
            CALCULATE (
                SELECTEDVALUE ( 'Table'[_monthNum] ),
                FILTER ( ALLSELECTED ( 'Table' ), 'Table'[_Month] = _currentMonth )
            )
        VAR _PreviousMonthNum =
            CALCULATE (
                MAX ( 'Table'[_monthNum] ),
                FILTER ( ALLSELECTED ( 'Table' ), 'Table'[_monthNum] < _currentMonthNum )
            )
        VAR _previousMonth =
            CALCULATE (
                SELECTEDVALUE ( 'Table'[_Month] ),
                FILTER ( ALLSELECTED ( 'Table' ), 'Table'[_monthNum] = _PreviousMonthNum )
            )
        VAR _Current =
            MAX ( 'Sheet2'[Current Month Data] ) & SELECTEDVALUE ( Sheet2[Month] )
        VAR _Previous =
            MAX ( 'Sheet2'[Previous Month Data] ) & _previousMonth
        RETURN
            _Current & "-" & _Previous

    Finally you will get what you want.

     

     

     

     

    Best Regards

    Yilong Zhou

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

    • NadeemAhamed's avatar
      NadeemAhamed
      Icon for Helper V rankHelper V

      Anonymous 

       

      Thank you soo much for your valuable time to read and reply my post.

       

      actually i want to pass slicer month name in column header not in separate column.

       

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi NadeemAhamed ,

        I think the first thing you need to know is that in Power BI Desktop's tables, you can't dynamically change the names of the columns you put in by means like DAX, you can only change its style and static name.

        So in your case, I think if you want to implement your needs, maybe you can try using Card Visual. The card is not in the form, but it can be returned in the form you want.

        Measure = "Current Month   " & SELECTEDVALUE(Sheet2[Month]) & "   Data"

         

         

         

        Best Regards

        Yilong Zhou

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