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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
emillia1991
New Member

Adding category on the x-axis for the graph based on measures

Dear community,

 

I want to produce a bar chart in Power BI showing the differences between two years for: sales, average sales, total hours and total training. I want to split it into two categories: Operational (sales and avarage sales) and Training (total hours and total training). Now my bar chart looks like this:

 

emillia1991_0-1662038547822.png

 I want it to be interactive, i.e I want to choose two years in the slicer. The differences have been computed by measures:

 

E.g. the percentage difference for sales:

 

D_sales = 100*(DIVIDE(
    [Diff_sales],
    CALCULATE(
        SUM('Sheet1'[sales]),
        FILTER('Sheet1',Sheet1[year]=MIN(
            'Sheet1'[year]))
    )
))
 
 
Diff_sales = IF(
    HASONEVALUE('Sheet1'[year]),
    BLANK (),
    CALCUlATE(
        SUM(Sheet1[sales]),
        FILTER('Sheet1','Sheet1'[year]=MAX(Sheet1[year]
        ))
)
        - CALCULATE(
            SUM(Sheet1[sales]),
            FILTER('Sheet1','Sheet1'[year]=MIN(Sheet1[year]
            ))
        )
)
 
I don't know how to tell Power BI that D_sales belongs to Operational and it should show it on the x-axis. 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@emillia1991 , Use a separate Date or Year Table, joined with your table

 

new measure =
var _max = maxx(allselected(Date),Date[Year])
var _min = minx(allselected(Date),Date[Year])
return
calculate( sum(Table[Value]), filter('Date', 'Table'[Date] =_max )) - calculate( sum(Table[Value]), filter('Date', 'Table'[Date] =_min ))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@emillia1991 , Use a separate Date or Year Table, joined with your table

 

new measure =
var _max = maxx(allselected(Date),Date[Year])
var _min = minx(allselected(Date),Date[Year])
return
calculate( sum(Table[Value]), filter('Date', 'Table'[Date] =_max )) - calculate( sum(Table[Value]), filter('Date', 'Table'[Date] =_min ))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.