Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Multi X Axis with different Columns/Measures.

I am looking for a Power BI visual just like the below snapshot.

 

 

The data looks like the below table

 

DateCountrySupplier PartSub PartTotal QtyTotal Sales
02-06-2025AXX1Y1100040000
03-06-2025AXX1Y120030000
04-06-2025AXX1Y130015000
05-06-2025AXX1Y140010000
06-06-2025AXX1Y1500020000
07-06-2025BYX2Y2600035000
08-06-2025BYX2Y240012000
09-06-2025BYX2Y23000080000
10-06-2025BYX2Y21000

10000

 

I need to have 2 visuals, where one will give Supplier A details and One Supplier B details basis the selection from Single Slicer Supplier. I need to have bar graphs for QTD, YTD, Month(Current), Current Year. It should give me bars of Average Price = (Total Sales/Vol)

 

Anyone who knows how this can be done?

 

I am unable to name the X -axis. I have used the column chart but ended up having Y-axis but no label on X-Axis

8 Replies

  • Hey Anonymous ,

    To achieve a Power BI visual like the one you sketched with multi-bar (column) visuals showing QTD, YTD, Current Month, and Current Year comparisons based on Average Price.

    Objective

    Create two visuals (for Supplier A and B) showing Average Price = Total Sales / Total Qty

    With these metrics on the X-axis:

    • QTD (Quarter-To-Date)

    • YTD (Year-To-Date)

    • M (Current Month)

    • Y (Current Year Total)

    Step 1: Build Measures

    In your Power BI data model, create measures using DAX:

    AvgPrice_QTD :=
    VAR QTD_Sales = CALCULATE(SUM('Table'[Total Sales]), DATESQTD('Table'[Date]))
    VAR QTD_Qty = CALCULATE(SUM('Table'[Total Qty]), DATESQTD('Table'[Date]))
    RETURN DIVIDE(QTD_Sales, QTD_Qty)
    
    AvgPrice_YTD :=
    VAR YTD_Sales = CALCULATE(SUM('Table'[Total Sales]), DATESYTD('Table'[Date]))
    VAR YTD_Qty = CALCULATE(SUM('Table'[Total Qty]), DATESYTD('Table'[Date]))
    RETURN DIVIDE(YTD_Sales, YTD_Qty)
    
    AvgPrice_Month :=
    VAR M_Sales = CALCULATE(SUM('Table'[Total Sales]), DATESMTD('Table'[Date]))
    VAR M_Qty = CALCULATE(SUM('Table'[Total Qty]), DATESMTD('Table'[Date]))
    RETURN DIVIDE(M_Sales, M_Qty)
    
    AvgPrice_Year :=
    VAR YearStart = DATE(YEAR(TODAY()), 1, 1)
    VAR Y_Sales = CALCULATE(SUM('Table'[Total Sales]), 'Table'[Date] >= YearStart)
    VAR Y_Qty = CALCULATE(SUM('Table'[Total Qty]), 'Table'[Date] >= YearStart)
    RETURN DIVIDE(Y_Sales, Y_Qty)

    Step 2: Create an Unpivoted Supporting Table for Visual

    Create a new table:

    AvgPriceView =
    DATATABLE(
        "Period", STRING,
        "MeasureName", STRING,
        {
            {"QTD", "AvgPrice_QTD"},
            {"YTD", "AvgPrice_YTD"},
            {"M", "AvgPrice_Month"},
            {"Y", "AvgPrice_Year"}
        }
    )

    Then, create a switch measure:

    AvgPrice_Switch :=
    SWITCH(
        SELECTEDVALUE(AvgPriceView[MeasureName]),
        "AvgPrice_QTD", [AvgPrice_QTD],
        "AvgPrice_YTD", [AvgPrice_YTD],
        "AvgPrice_Month", [AvgPrice_Month],
        "AvgPrice_Year", [AvgPrice_Year]
    )

    Step 3: Create the Visual

    1. Use a Column Chart.

    2. Place AvgPriceView[Period] on the X-axis.

    3. Use the AvgPrice_Switch as Values (Y-axis).

    4. Add a Slicer for Supplier to allow dynamic filtering between Supplier A and B.

    For Detailed Information:

    Microsoft Docs – Time Intelligence Functions

    Radacad – How to Use a Disconnected Table for Dynamic Axis

    SQLBI – Using SWITCH for Multiple Measures

    Power BI Community – Custom X Axis in Column Chart

     

    If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


    Best Regards,
    Nasif Azam

    • Anonymous's avatar
      Anonymous
      Not applicable

      This seems to be good,

      But if in the Slicer 2 Suppliers are selected, how do I show one visual for Supplier A and another visual for Supplier B? That was also a part of the use case. Can you help me with it?

      • Nasif_Azam's avatar
        Nasif_Azam
        Super User

        I provide you the detailed solution with steps, which will be very easy to impliment for you. To handle multiple supplier selections (e.g., both A and B) and still show separate visuals for each, you'll need to do a little modeling and setup in your Power BI report.

        Solution

        You’ll create two visuals, each filtered to display data only for one supplier, regardless of what's selected in the slicer.

        Step 1: Add a Slicer for Supplier

        • Add a slicer visual and put the Supplier field in it.

        • Enable multi-select if needed (so users can pick A and B together).

        Step 2: Create Two Measures with Supplier Filters

        AvgPrice_QTD_SupplierA :=
        VAR QTD_Sales = CALCULATE(SUM('Table'[Total Sales]), DATESQTD('Table'[Date]), 'Table'[Supplier] = "A")
        VAR QTD_Qty = CALCULATE(SUM('Table'[Total Qty]), DATESQTD('Table'[Date]), 'Table'[Supplier] = "A")
        RETURN DIVIDE(QTD_Sales, QTD_Qty)

        Repeat similarly for:

        • AvgPrice_YTD_SupplierA
        • AvgPrice_Month_SupplierA
        • AvgPrice_Year_SupplierA

        And do the same for Supplier B with 'Table'[Supplier] = "B".

        Step 3: Create a Period Selector Table (Disconnected)

        PeriodTable =
        DATATABLE(
            "Period", STRING,
            {
                {"QTD"},
                {"YTD"},
                {"Month"},
                {"Year"}
            }
        )

        Create a slicer using this table, or use it as your X-axis in visuals.

        Step 4: Create SWITCH Measures for Each Supplier

        Supplier A:

        AvgPrice_Switch_SupplierA :=
        SWITCH(
            SELECTEDVALUE(PeriodTable[Period]),
            "QTD", [AvgPrice_QTD_SupplierA],
            "YTD", [AvgPrice_YTD_SupplierA],
            "Month", [AvgPrice_Month_SupplierA],
            "Year", [AvgPrice_Year_SupplierA]
        )

        Supplier B:

        Do the same with [AvgPrice_QTD_SupplierB], etc.

        Step 5: Build the Visuals

        • Create two clustered column charts:

          • One for Supplier A using PeriodTable[Period] on X-axis and AvgPrice_Switch_SupplierA as values.

          • One for Supplier B using the corresponding measure.

        • Hide axis titles and manually label the visuals above/below as “Supplier A” and “Supplier B” for clarity.

         

        For Detailed Information:

        Microsoft Docs – Time Intelligence Functions

        Radacad – How to Use a Disconnected Table for Dynamic Axis

        SQLBI – Using SWITCH for Multiple Measures

        Power BI Community – Custom X Axis in Column Chart

         

        If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


        Best Regards,
        Nasif Azam

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Thank you for reaching out to the Microsoft Fabric Community.

     

    As correctly explained by danextian  and Nasif_Azam , using a calculation group on the X-axis will display QTD, MTD, YTD, and Year as separate categories in a single visual. Just ensure "Concatenate labels" is turned off if the labels aren’t showing properly.

    If you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If the response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous 

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If the response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

     

    Thank you.