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
beuthner71
New Member

SUBTRACTION BETWEEN DIFFERENT TABLES, WITH FILTER BY DATE

Dear,

I'm new to Power Bi (six months more or less), and so far I've solved all the questions by searching for tutorials and examples on the internet, but unfortunately I'm not finding a solution to my problem anywhere.

I have two spreadsheets (DAP & DERIVA) with more or less 30,000 lines each.

 

In the DAP & DERIVA spreadsheet I have the same columns:

 

beuthner71_0-1703102934355.png

(A) CODE: It would be the same as the product code. NO code in the DAP spreadsheet is the same as the one in the DERIVA spreadsheet.

(B) DATE: Date on which the FEE was collected for the sale of the product. Each CODE is checked several times a month to find out the FEE for the day.

(C) FEE: Fee negotiated on the day of verification.

 

What I need is:

That the FEES of all CODES grouped in the DAP spreadsheet, and filtered by dates, are subtracted from all CODES in the DERIVA spreadsheet (does not need to be grouped), but which have the same DATE in the DAP spreadsheet.

 

EXAMPLE:

 

beuthner71_1-1703103236594.png

 

beuthner71_2-1703103331839.png

 

ACTION 1: GROUPED DAP BY CODE

 

beuthner71_3-1703103856076.png

 

ACTION 2: IDENTIFY WHICH DATES ARE THE SAME IN THE DERIVA SPREADSHEET, REGARDLESS OF THE CODE.

 

beuthner71_6-1703105570980.png

 

ACTION 3: SUBTRACT FEES PER GROUPING.

 

beuthner71_7-1703105849231.png

ACTION 4: TRANSFORM THE RESULT OF SUBTRACTIONS IN ABSOLUTES

beuthner71_8-1703106253028.png

 

ACTION 5: LIST THE LOWEST VALUES PER GROUP.

beuthner71_9-1703106636786.png

 

If anyone in the group has a link of any kind (PDF, Youtube, DOC, etc.) that helps me understand how to deal with this problem, I would greatly appreciate it.

The explanations I found on the internet talk about multiplication, average, division, but I couldn't find anything about subtraction of values with dates which are repeated.

I spent some time trying to understand Line Context and Filter Context, as I believe that (among other things) this is a subject that I need to delve deeper into.

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @beuthner71 ,

 

According to your description, here are my steps you can follow as a solution.

(1) Click on "transform data" to enter the power query, merge the two tables with the date column and expand it. Refer to the pbix file.

vtangjiemsft_0-1703138997252.png

vtangjiemsft_1-1703139085601.png

(2) We can create measures.

ABS_Fee = ABS(SUM('Merge1'[DAP_FEE])-SUM('Merge1'[DERIVA_FEE]))
Flag = IF([ABS_Fee]=MINX(FILTER(ALLSELECTED('Merge1'),'Merge1'[DAP_CODE]=MAX('Merge1'[DAP_CODE]) && 'Merge1'[DATE]=MAX('Merge1'[DATE])),[ABS_Fee]),1,0)

(3) Place [Flag=1] on the screening of the visual object and then the result is as follows.

vtangjiemsft_2-1703139241646.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

2 REPLIES 2
v-tangjie-msft
Community Support
Community Support

Hi @beuthner71 ,

 

According to your description, here are my steps you can follow as a solution.

(1) Click on "transform data" to enter the power query, merge the two tables with the date column and expand it. Refer to the pbix file.

vtangjiemsft_0-1703138997252.png

vtangjiemsft_1-1703139085601.png

(2) We can create measures.

ABS_Fee = ABS(SUM('Merge1'[DAP_FEE])-SUM('Merge1'[DERIVA_FEE]))
Flag = IF([ABS_Fee]=MINX(FILTER(ALLSELECTED('Merge1'),'Merge1'[DAP_CODE]=MAX('Merge1'[DAP_CODE]) && 'Merge1'[DATE]=MAX('Merge1'[DATE])),[ABS_Fee]),1,0)

(3) Place [Flag=1] on the screening of the visual object and then the result is as follows.

vtangjiemsft_2-1703139241646.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

amitchandak
Super User
Super User

@beuthner71 , Based on what I got so far is merge two tables based on date in Power query 

 

Merge Tables (Power Query) : https://youtu.be/zNrmbagO0Oo

 

 

Or create a dax column in DERIVA  using DAP

 

new column = DERIVA [Fee] - Sumx(filter(DAP, DERIVA [Date]= DAP[Date]) , DAP[FEE])

refer 4 ways (related, relatedtable, lookupvalue, sumx/minx/maxx with filter) to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

 

 

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.