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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
tvaishnav
Helper IV
Helper IV

DAX To calculate to date for some categories and current Mth for others

I have data as follows :

Name of table is 'Net Cash Position'

Metric | Mth | Value

Billed  | Jan 2022        |100

Billed  | Feb 2022        |200

Billed  | Mar 2022       |300 

AR      | Jan 2022        |50

AR      | Feb 2022        |25

AR      | Mar 2022        |30

 

There is date table that is filtering Mth column.

I want to display this data in matrix as follows :

 

Billed | 600 (To date calculation)

AR     | 30   (Value per current month that is selected in data slicer)

 

I can do this in SQL but I am looking for DAX solution.

 

I tried this solution :

 

 

Value  = SUMX('Net Cash Position',
                            IF('Net Cash Position'[Metric] =  "AR"
                            ,('Net Cash Position'[Val])
                            ,CALCULATE(SUM('Net Cash Position'[Val]),'Net Cash Position'[Mth]<= MAX('Date'[Date]))))

 

But shows results as if condition is always true.

 

 

1 ACCEPTED SOLUTION

Hi,

Download the PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
lbendlin
Super User
Super User

Value = 
var m = max('Net Cash Position'[Mth])
return if(SELECTEDVALUE('Net Cash Position'[Metric])="AR",sum('Net Cash Position'[Val]),sumx(filter(allselected('Net Cash Position'),'Net Cash Position'[Mth]<=m && 'Net Cash Position'[Metric]="Billed"),'Net Cash Position'[Val]))

see attached

@lbendlin That certainly helps. I read more about the functions you used and it does make sense. However, it seems that DAX code does not give desired result if I have relationships coming in. Can you look at the modified pibx file that I have attached? I tried attaching .pbix file with sample data but I get a error message. I really appreciate your time.

 

I have a model that looks like this:

 

tvaishnav_0-1655771285214.png

 

I have slicer on job name and month. The formula stops working in this set up. User would select one value in both job and name slicer.

 

 

 

 

Post your sample pbix on a file service.

Hi,

Download the PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you so much for this. I tested this and it worked great. I did modify this a bit to change measure from year to date  to To date from the beginning of project.

Thank you so much for your time.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.