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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PreetiSahu321
Helper I
Helper I

Subtract two columns from different table per monthly basis using DAX in power bi

Hello Power BI Community Members,

 

I have two tables as Orders and Invoices. There is one common column in both Orders and Invoices tables i.e. BillDate (Date and Time Datatype). In the Orders table, It has one column named as a Net value whose data type is the Whole Number. Similarly, in the Invoices table, It has a column named as Sales US$ (Whole Number Datatype). As per my requirement, I want to subtract these two columns per monthly basis. Let me explain to you properly.

 

By using the below screenshot, you can see below are my two tables as Orders and Invoices. I want to subtract the values from Net value to Sales US$ of the current month. As this is November month is going on, So it will subtract the values for the current month only. i.e. (132453-10600=121853)

 

12.png

 

As I am new to Power BI, I do not have much knowledge about this Power BI DAX rules. Please, Can anyone suggest to me what I have to do in this case?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Measure = 
VAR NetValue = CALCULATE(SUM(Orders[Net value]))
VAR yyyy = MAXX(Orders,Orders[Req.dlv.dt].[Year])
VAR MM = MAXX(Orders,Orders[Req.dlv.dt].[MonthNo])
VAR Sales = CALCULATE(SUM(Invoices[Sales US$]),FILTER(ALL(Invoices),YEAR(Invoices[Bill Date])=yyyy&&MONTH(Invoices[Bill Date])=MM))
RETURN NetValue-Sales

@PreetiSahu321

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Column = 'Order'[Net Value]-LOOKUPVALUE(Invoice[Sales US],Invoice[Year],'Order'[Year],Invoice[Month],'Order'[Month],0)

Hi @Anonymous ,

 

Can you suggest to me how you have used "Invoice[Year], 'Order'[Year], Invoice[Month], 'Order'[Month]" in the above formula. Because when I am adding this in the new column, it is showing me an error that those columns are not existing in the tables.

 

That's why I have added this below formula in the column and it is showing me the wrong value as you can see in the below screenshot.

 

11111111.png

 

One more thing I want to tell is, For the Invoices table, it is Bill Date whereas, in the Orders table, it is Req.dlv.dt.

As I am new to Power BI, I don't have much knowledge about Dax. Please suggest me what I have to do?

Anonymous
Not applicable

@PreetiSahu321  Please create column in Order table 

Column = 'Order'[Net value]-LOOKUPVALUE(Invoice[Sales],Invoice[Bill Date],'Order'[Req.dlv.dt])

@Anonymous ,

 

I have created a new column in the Orders list and applied this formula but it is not working for me and appearing the below error. Also, In the Invoices list, the Bill Date is "MM/DD/YYYY" in format. Similarly, in the Orders list, the Req.dlv.dt is "MM/DD/YYYY" in format.

 

11111111.png

 

Its better to create a date table. Then use the date on the date table for reporting.

 

Connect the two table using date

ie: 

 

Measure = SUM(Order[Net Value]) - SUM(Invoices[Sales US$])

11111.png

Hi @kmagat ,

 

As you said, I have created a Date table and made a relationship with those two tables (Orders and Invoices). But still, it is not showing me the correct value that I am expecting. You can see my sample report by using this below link:

 

Sample Report 

Anonymous
Not applicable

Measure = 
VAR NetValue = CALCULATE(SUM(Orders[Net value]))
VAR yyyy = MAXX(Orders,Orders[Req.dlv.dt].[Year])
VAR MM = MAXX(Orders,Orders[Req.dlv.dt].[MonthNo])
VAR Sales = CALCULATE(SUM(Invoices[Sales US$]),FILTER(ALL(Invoices),YEAR(Invoices[Bill Date])=yyyy&&MONTH(Invoices[Bill Date])=MM))
RETURN NetValue-Sales

@PreetiSahu321

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors