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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.