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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Abevann
Helper III
Helper III

I have to mix two tables and get a result by week

Guys,

 

I have been working on a dashboard and got stuck; I have a couple of tables (SQL query) 

DateInputOutput
20/01/2021 1
22/01/2021 1
02/02/2021 0
12/02/2021 1
08/03/2021 2
18/03/2021 1
23/03/2021 1
26/03/2021 1

 

DateMonthly stock
01/01/20218
01/02/20216
01/03/20215
01/04/20210

 

On first table, I have the input and output from warehouse; in second one, I have the stock in warehouse. What I am looking for, is to get a table with the stock and substract the inputs or outputs of the warehouse as on attached table:

Product codeYear-weekInputOutputMonthy stockWeekly stock
UC48C22021-01  88
UC48C22021-04 2 6
UC48C22021-06 066
UC48C22021-07 1 5
UC48C22021-10  55
UC48C22021-11 2 3
UC48C22021-12 1 2
UC48C22021-13 2 0

 

Any suggestion for this issue?

 

Thanks a lot, regards,

Abelardo

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Abevann 

 

First, you need to append two tables in power query.

vzhangti_0-1639028480049.png

 

Then use the following calculation column to output the results you want.

Week = WEEKNUM([Date],1)
Weekly stock =
MAX ( Append1[Monthly stock] )
    - CALCULATE (
        SUM ( Append1[Output] ),
        FILTER ( Append1, [Week] <= EARLIER ( Append1[Week] ) )
    )
Year-week = YEAR([Date])&"-"&[Week]

vzhangti_1-1639028672590.png

 

The "week" column needs to be reserved, otherwise the view cannot be sorted.

vzhangti_2-1639028720570.png

 

Best Regards,

Community Support Team _Charlotte

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

1 REPLY 1
v-zhangti
Community Support
Community Support

Hi, @Abevann 

 

First, you need to append two tables in power query.

vzhangti_0-1639028480049.png

 

Then use the following calculation column to output the results you want.

Week = WEEKNUM([Date],1)
Weekly stock =
MAX ( Append1[Monthly stock] )
    - CALCULATE (
        SUM ( Append1[Output] ),
        FILTER ( Append1, [Week] <= EARLIER ( Append1[Week] ) )
    )
Year-week = YEAR([Date])&"-"&[Week]

vzhangti_1-1639028672590.png

 

The "week" column needs to be reserved, otherwise the view cannot be sorted.

vzhangti_2-1639028720570.png

 

Best Regards,

Community Support Team _Charlotte

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

 

 

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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