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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
matteomatilde
Frequent Visitor

Combine rows from multiple columns into a new column

Hello everyone.

I've got these two tables:

  • FACT_STK
STK_IDSTK_ITM_IDSTK_DATESTK_QTYSTK_WHS
1I015424 Apr 2150WHS1
2I015426 Apr 21 30WHS1
4I015430 Apr 2120WHS1
5I01542 May 2115WHS1

 

  • FACT_MOV
MOV_IDMOV_ITM_IDMOV_DATEMOV_QTYMOV_CAUMOV_WHS
1I015425 Apr 2120SaleWHS1
2I01541 May 215SaleWHS1

 

As you can see from the stock quantities, 10 pieces of I0154 were sold in a day between 26 and 30 April, but no movements were registrated in the FACT_MOV.

In addition, 5 pieces of I0154 wew sold on May 1st, but the stock was updated the day after.

 

My aim is to calculate the average stock for each item, calculated as the sum of (stk_qty * days_of_stock) divided by (total days of stock)

 

so I thought that I could create a table with all the dates (from the minimum date of fact_mov and fact_stk to the maximum date) and create some columns like these:

 

ITM_IDDATESTK_QTYMOVEMENTCORRECT_STKWHS_ID
I015424 Apr 2150050WHS1
I015425 Apr 21502030WHS1
I015426 Apr 21 30030WHS1
I015427 Apr 2130030WHS1
I015428 Apr 2130030WHS1
I015429 Apr 2130030WHS1
I015430 Apr 21201020WHS1
I01541 May 2120515WHS1
I01542 May 2115015WHS1

 

How can I implement it in Power BI? Do you have a smarter idea to achieve my goal? I leave you also the pbix file: https://www.dropbox.com/s/m2z3g5xf19n7ji8/matteo%20-%20Copia.pbix?dl=0

 

Thanks.

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Tweak the code according to your own dataset,

Screenshot 2021-05-29 113251.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thank you so much, it worked! Do you know how can I calculate the average stock, intended as sum of (CORRECT_STK* numbero of days of stock) divided by (total days of stock)

 

In the example it would be (50*1 + 30*4 + 20*2 + 15*2) / 9 = 26,67 days

 

Thank you!

Helpful resources

Announcements
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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.