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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
AlvinLy
Helper II
Helper II

How to reference a column in a Power BI Measure

Hello Microsoft Community,

 

It feels like the more I learn about Power BI and DAX, the less I actually know. 

 

I've been working with measures recently since one of our Power BI model references data in Direct Query mode rather than Import Mode, therefore I've been transforming some of my calculated columns to measures to accomodate this. One issue I've been coming up with is referencing another column in another measure.

 

So here is the scenario. I have a fact table with activity ID, schedule date, and project ID. Where project ID, connects to a dimension table used as a filter to see which activity belong in which project. I have a date table that gives us the period end dates from 2021 to 2030. For my company it is every other Friday. I previously had a calculated column that took all schedule date for every activity and show what end period date it belongs to. I converted that to a measure shown below:

 

 

End Period Date Measure = 
VAR enddate = SELECTEDVALUE('Fact_Table'[Schedule Date])
RETURN
CALCULATE(
    MIN(Date_Table[End Period]),
    Filter(Date_Table, Date_Table[End Period] > enddate)
)

 

  

When I throw this into a Power BI table visual this measure works as intended, similar to a calculated column. The trouble i'm running into is when i filter by project, say i only want schedule activties from project A, the power BI visual shows ALL activities, and if the activity is NOT in project A it simply gives the smallest end period date in my date table. So to give a quick visual since i can't upload my data (directquery to datalake)

 

What my fact table looks like:

Schedule ActivitySchedule DateProject
Walk2024-01-03A
Eat2024-01-15A
Sleep2024-02-12B

 

What my previous calculated column when filtering to Project A looked like:

Schedule ActivitySchedule DateEnd Period
Walk2024-01-032024-01-05
Eat2024-01-152024-01-19

 

What the measure outputs when filtering for Project A looks like:

Schedule ActivitySchedule DateEnd Period Date
Walk2024-01-032024-01-05
Eat2024-01-152024-01-19
Sleep2024-02-122021-01-08

 

I think this problem occurs with the use of "SELECTEDVALUE". The filter, for some reason keeps all schedule activity instead of filtering it out, and since that filter context doesn't have a schedule date for that activity it uses BLANK() as enddate variable. Thats my hypothesis. 

 

So the TLDR, is there an alternative of SELECTEDVALUE in a measure, in general, and in my specific scenario. I know that max, min, sum, could potentially be used, but in my scenario it won't make sense. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @amitchandak ,thanks for the quick reply, I'll add further.

Hi @AlvinLy ,

Regarding your question, please modify your dax expression.

 

End Period Date = 
VAR _a = SELECTEDVALUE(FactTable[Schedule Date])
RETURN  IF(ISBLANK(_a),BLANK(),MINX(FILTER('DateTable','DateTable'[Date] >= _a),[Date]))

 

vzhouwenmsft_0-1715758965864.png

This is my understanding: the schedule time for 'Sleep' is filtered by the slicer to null. later you use it as a condition for filtering the date table, and since it's null, it doesn't filter any data. So it returns the smallest date in the date table. As long as the result of the measure is not null, it will not be automatically omitted by Power BI.

View solution in original post

4 REPLIES 4
AlvinLy
Helper II
Helper II

Hello,

 

That worked perfectly in my small sample data! I will now try it on my larger dataset, but if anything the issues will be from other inputs and not from this null and filter issue

 

Thanks,

amitchandak
Super User
Super User

@AlvinLy , Try measure like

 

End Period Date Measure =
VAR enddate = Max('Fact_Table'[Schedule Date])
RETURN
CALCULATE(
MIN(Date_Table[End Period]),
Filter(all(Date_Table), Date_Table[End Period] > enddate)
)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello Amitchandak

 

Thank you for your suggestion. I get the same result. I'm beginning to wonder if it's because I have a DirectQuery rather than an imported model that I come up with this issue, but it is odd since I think the formula that I have is rather simple.

 

Other than SELECTEDVALUE, MAX, and MIN, what are other typical ways we would select the column in the same row using a measure? 

 

I assume the logic to either MAX or MIN is that during the row context of the calculation there is only one value so it chooses that value regardless if it's MAX or MIN. That makes sense in my mind, but not sure why it's not working.

Anonymous
Not applicable

Hi @amitchandak ,thanks for the quick reply, I'll add further.

Hi @AlvinLy ,

Regarding your question, please modify your dax expression.

 

End Period Date = 
VAR _a = SELECTEDVALUE(FactTable[Schedule Date])
RETURN  IF(ISBLANK(_a),BLANK(),MINX(FILTER('DateTable','DateTable'[Date] >= _a),[Date]))

 

vzhouwenmsft_0-1715758965864.png

This is my understanding: the schedule time for 'Sleep' is filtered by the slicer to null. later you use it as a condition for filtering the date table, and since it's null, it doesn't filter any data. So it returns the smallest date in the date table. As long as the result of the measure is not null, it will not be automatically omitted by Power BI.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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