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 September 15. Request your voucher.

Reply
kashahzad
Frequent Visitor

Dax measures functioning of and on

Hi,

 

It's happening to me frequently now and I am getting frustrated. I created a dax measure to calculate the sales in specific regions and it worked initially and then suddenly it stopped and then the next day it started working again and then again it stopped working, is this a bug?  Below is the DAX formula and this is just one example.

 

sales by region = var reg = selectedvalue('Orders'[Region])
                                            return
                                            calculate(sum(Orders[Sales]), filter(Orders,'Orders'[Region]= reg))
7 REPLIES 7
sturlaws
Resident Rockstar
Resident Rockstar

Hi @kashahzad 

 

the measure you have written will only work if a single region is selected. I am guessing your experience in whether this work or not is related to this.


Cheers,
Sturla

@sturlaws 

Hi Sturlaws,

 

Thank you for looking into it and replying, do you find this formua incorrect? because it's not working and pulling nothing, but it was working previously and showing the sales by region and this is why I am confused.

 

sales by region = var reg = selectedvalue('Orders'[Region])
return   
calculate(sum(Orders[Sales]), filter(Orders,'Orders'[Region]= reg))

the code works:
image.png

as long as there is a single value for region in the current context. So if I choose two values in the slicer, it returns blank:
image.png

 

This is the expected behaviour, the SELECTEDVALUE-function returns blank if there is more than 1 distinct value in the current context. 

 

What kind of visual are you using this measure in? And what are you using to filter it?

@sturlaws 

 

I was trying to get the total sale value per region, so there are four regions and I want the formula to sum the sales within these four regions and show values in a table or the stacked bar chart.

 

North     ###

West      ###

South    ###

East       ###

Could you share the report you are working on? Or create a sample report where the issue is recreated and share it?

But then it is sufficient to write your measure as sales = sum(orders[sales]). The Power BI visual will handle the grouping into regions for you when it is on the axis of a visual

@sturlaws 

I totally agree, but since I am trying to learn Dax, so I am trying different scenarios to help me understand the behavior of different functions when combined together specially when variables are used to make the formulas efficient.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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