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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
ShubhamMudliar
New Member

DAX for computing two measures based on selected date

Hi all, I have a scenario which I am working on . Below is an export from POwer BI report. 

ShubhamMudliar_0-1710002513860.png

I two table : Effective date and transactions table. Invoice amount , collected amount and open balance are DAX measures.

Below are their formula:
1)InvoiceAmount:=
CALCULATE(SUM(FACTCustomerTransactions[AMOUNTMST]),
FILTER ( FACTCustomerTransactions, FACTCustomerTransactions[TransTypeName] <> "Write off"

),Transactions[Transdate]<=MAX(EffectiveDate[Date]))
2)Collected:=
CALCULATE(SUM(FACTCustomerTransactions[SETTLEAMOUNTMST]) + ( [PPDAmount] + [WriteOff]),
FACTCustomerTransactions, FACTCustomerTransactions[TransTypeName] <> "Write off",Transactions[Transdate]<=MAX(EffectiveDate[Date])

3) Open AR:=
CALCULATE (
[Balance]
, Transactions[TRANSDATE]<= MAX(EffectiveDate[Date])
) ------where Balance =Invoice amount -collected amount
I have an existing relationship between the two table. 
Now I  want to create a measure  as per below scenarios:

1) when user selects effective date after the due date (refer image) then the  [balance] should show invoice - collected

2) when user selects effective date between invoice date and duedate (refer image) then Collected should be zero as nothing get collected  before the due date . And that amount should get reflected in [balance].

Appreciate any help !!

2 REPLIES 2
ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

Demo Data:

ValtteriN_4-1710089494917.png

 

ValtteriN_3-1710089453984.png

 

Data model:

ValtteriN_2-1710088913438.png

 

Dax:

Balance =
var _t = SUM(Invoices[Total Amount])
 var _due = MAX(Invoices[Due Date])
 var _invoice = MAX(Invoices[Invoice Date])
 var _seldate = MAX('Calendar'[Date])
 var _id = MAX(Invoices[ID])
 RETURN
_t -
IF(_seldate<=_due && _seldate >=_invoice,_t,
CALCULATE(SUM('Transaction'[Value]),ALL('Transaction'),'Transaction'[Date]<=_seldate,_id='Transaction'[ID])) //collected amount
Here the last 2 rows are collected amount.


End result:
ValtteriN_5-1710089719377.png

 

ValtteriN_6-1710090065955.png

 

ValtteriN_7-1710090078669.png

 

Here the conditions are fulfilled and when the selection changes the balance changes along.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks for the solution. It worked!!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.