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
Anonymous
Not applicable

Detecting the previous row in Power Query - handling a text file

Hi,

I need to import more rows from several stock info text files, treating them inside power query and then producing some KPIs.

I need to manage a granularity at day and hour level.

The record layout for a text file is:

WH_SITE YYYYMM B_DDhh-E_DDhh MAIN_VALUE OVR OB_DDhh-OE_DDhh VALUE_TO_OVERRIDE OVR OB_DDhh-OE_DDhh VALUE_TO_OVERRIDE,

where

WH_SITE = Warehouse location code

YYYYMM = validity forecast year and month

B_DDhh = validity begin forecast day and hour

E_DDhh = validity end forecast day and hour

MAIN_VALUE = initial stock value, valid between B_DDhh and E_DDhh

OVR = optional section to override the initial value for a specific validity period (I could have 0 or 1 or max 5 OVR sections)

OB_DDhh-OE_DDhh = begin and end of a validity period for a stock value to override

VALUE_TO_OVERRIDE = stock value that overrides the initial stock value for a specific validity period

 

Here a record sample:

SITE01 202104 0709-0718 5000 OVR 0712-0713 4500 OVR 0715-0716 4200

 

I've applied several transformation steps inside Power Query, obtaining a such result:

 

pmscorca_0-1621708044294.png

 

but I need to obtain a such result, before using some DAX logics to obtain the final KPIs:

 

pmscorca_1-1621708157176.png

The override operation occurs after the related end of the validity period.

The override sections are optional, up to five ones.

I thought to detect the previous row to understand the passage from the old stock value to the new stock value to override. I cannot adding an index, I need to handle some millions of rows (I've expanded the validity period to split in date + time, hour for hour), perhaps I need to search the previous row respect to the WS_SITE and the VALIDITY_DATETIME less one hour.

 

Any suggests to me, please? Thanks

1 ACCEPTED SOLUTION
ERD
Super User
Super User

@Anonymous ,

You can create custom columns with if/else conditions and then delete old column. Something like this:

ERD_0-1621842205965.pngERD_1-1621842224110.pngERD_2-1621842284745.png

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

3 REPLIES 3
ERD
Super User
Super User

@Anonymous ,

You can create custom columns with if/else conditions and then delete old column. Something like this:

ERD_0-1621842205965.pngERD_1-1621842224110.pngERD_2-1621842284745.png

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

Sorry, I've tried more time to pasted the worked rows, but unsuccessfully!

Here, the last attempt accomplished:

 

WS_SITE VALIDITY_DATETIME INITIAL_STOCK_VALUE OVR_BEGIN_DATETIME_1 OVR_END_DATETIME_1 OVR_STOCK_VALUE_1 OVR_BEGIN_DATETIME_2 OVR_END_DATETIME_2 OVR_STOCK_VALUE_2
SITE_01 07/04/2021 09:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200
SITE_01 07/04/2021 10:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200
SITE_01 07/04/2021 11:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200
SITE_01 07/04/2021 12:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200
SITE_01 07/04/2021 13:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200
SITE_01 07/04/2021 14:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200
SITE_01 07/04/2021 15:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200
SITE_01 07/04/2021 16:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200
SITE_01 07/04/2021 17:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200
SITE_01 07/04/2021 18:00 5000 07/04/2021 12:00 07/04/2021 13:00 4500 07/04/2021 15:00 07/04/2021 16:00 4200

AlB
Super User
Super User

Hi @Anonymous 

Suggestion 1: Share your data in text-tabular format so that people trying to help can copy the table contents easily and run some tests. Just paste the table contents here, or share an excel file or a pbix with the data

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

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
Top Kudoed Authors