SOLVED

How to add a column with previous week values in Power Query/Power Bi

%3CLINGO-SUB%20id%3D%22lingo-sub-1895983%22%20slang%3D%22en-US%22%3EHow%20to%20add%20a%20column%20with%20previous%20week%20values%20in%20Power%20Query%2FPower%20Bi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1895983%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20set%20of%20weekly%20data%2C%20I%20just%20want%20to%20add%20the%20previous%20week's%20amount%20next%20to%20current%20week's%20Amount.%3C%2FP%3E%3CP%3EThis%20will%20help%20me%20to%20find%20the%20difference%20between%20the%20weeks.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attached%20he%20sample%20file.%20This%20data%20has%205%20columns%20and%20I%20want%20to%20get%20the%20Previous%20week's%20amount%20based%20on%20%22Subscription%20Code%22%20and%20%22Product%20Category%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sithi1984_0-1605628803160.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F234149iBE5D625F4849081C%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Sithi1984_0-1605628803160.png%22%20alt%3D%22Sithi1984_0-1605628803160.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1895983%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1896751%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20a%20column%20with%20previous%20week%20values%20in%20Power%20Query%2FPower%20Bi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1896751%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F872006%22%20target%3D%22_blank%22%3E%40Sithi1984%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20formula%20seems%20to%20work.%20I'll%20let%20you%20verify%20that%20it's%20producing%20the%20result%20you%20want.%3C%2FP%3E%3CP%3E%3DFILTER(%24D%242%3A%24D%24111%2C(%24A%242%3A%24A%24111%3DA2)*(%24C%242%3A%24C%24111%3DC2)*(%24F%242%3A%24F%24111%3DG2)%2C%22%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFILTER%20does%20require%20the%20most%20recent%20release%20of%20Excel%2C%20so%20if%20it%20doesn't%20work%20for%20you%20that%20could%20be%20the%20reason.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBy%20the%20way%2C%20you%20posted%20only%20a%20CSV%20file.%20It's%20necessary%20to%20put%20this%20into%20an%20XLS%20or%2C%20preferably%2C%20XLSX%20format.%20as%20I've%20done%20with%20the%20attached.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1896882%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20a%20column%20with%20previous%20week%20values%20in%20Power%20Query%2FPower%20Bi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1896882%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F425987%22%20target%3D%22_blank%22%3E%40mathetes%3C%2FA%3E%26nbsp%3BThanks%20for%20the%20quick%20response!%3C%2FP%3E%3CP%3EHow%20can%20we%20achieve%20this%20using%20Power%20query%20(M%20Language)%3F%3C%2FP%3E%3CP%3EAny%20idea%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1896909%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20a%20column%20with%20previous%20week%20values%20in%20Power%20Query%2FPower%20Bi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1896909%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F872006%22%20target%3D%22_blank%22%3E%40Sithi1984%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3EHow%20can%20we%20achieve%20this%20using%20Power%20query%20(M%20Language)%3F%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CEM%3EAny%20idea%3F%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENo%20idea.%20I've%20not%20used%20Power%20Query%20yet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20I'm%20not%20sure%20why%20you'd%20need%20to%20use%20it%2C%20given%20that%20FILTER%20works%20just%20fine.%20You%20might%20be%20taking%20a%20sledge%20hammer%20to%20a%20task%20that%20is%20readily%20accomplished%20with%20a%20normal%20everyday%20hammer.%20Or%2C%20a%20%22power%20tool%22%20when%20an%20everyday%20manual%20tool%20works%20easily.%20Take%20your%20pick%20of%20analogies.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1897519%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20a%20column%20with%20previous%20week%20values%20in%20Power%20Query%2FPower%20Bi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1897519%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F872006%22%20target%3D%22_blank%22%3E%40Sithi1984%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20merge%20the%20table%20with%20itself%20using%20Prior%20Week%20on%20left%20side%20and%20Week%20on%20right%20one%20%2C%20like%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powerquery%22%3E%3CCODE%3E%20%20%20%20%23%22Merged%20Queries%22%20%3D%20Table.NestedJoin(%0A%20%20%20%20%20%20%20%20%23%22Promoted%20Headers%22%2C%20%7B%22Subscription%20Code%22%2C%20%22Product%20Category%22%2C%20%22Prior%20Week%22%7D%2C%0A%20%20%20%20%20%20%20%20%23%22Promoted%20Headers%22%2C%20%7B%22Subscription%20Code%22%2C%20%22Product%20Category%22%2C%20%22Week%22%7D%2C%0A%20%20%20%20%20%20%20%20%22Promoted%20Headers%22%2C%0A%20%20%20%20%20%20%20%20JoinKind.LeftOuter%0A%20%20%20%20)%2C%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EJust%20expand%20Amount%20after%20that%20and%20apply%20desired%20cosmetic.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1897646%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20a%20column%20with%20previous%20week%20values%20in%20Power%20Query%2FPower%20Bi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1897646%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F425987%22%20target%3D%22_blank%22%3E%40mathetes%3C%2FA%3E%26nbsp%3B%20Thank%20you%20both%20for%20the%20solution.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1899281%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20a%20column%20with%20previous%20week%20values%20in%20Power%20Query%2FPower%20Bi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1899281%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F872006%22%20target%3D%22_blank%22%3E%40Sithi1984%3C%2FA%3E%26nbsp%3B%2C%20glad%20to%20help%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I have a set of weekly data, I just want to add the previous week's amount next to current week's Amount.

This will help me to find the difference between the weeks.

 

I have attached he sample file. This data has 5 columns and I want to get the Previous week's amount based on "Subscription Code" and "Product Category".

 

Sithi1984_0-1605628803160.png

 

9 Replies

@Sithi1984 

 

This formula seems to work. A quick and superficial review tells me that it's producing the result you want.

=FILTER($D$2:$D$111,($A$2:$A$111=A2)*($C$2:$C$111=C2)*($F$2:$F$111=G2),"")

 

FILTER does require the most recent release of Excel, so if it doesn't work for you that could be the reason. 

 

By the way, you posted only a CSV file. It's necessary to put this into an XLS or, preferably, XLSX format. as I've done with the attached.

 

@mathetes Thanks for the quick response!

How can we achieve this using Power query (M Language)?

Any idea?

@Sithi1984 

 

How can we achieve this using Power query (M Language)?

Any idea?

 

No idea. I've not used Power Query yet.

 

And I'm not sure why you'd need to use it, given that FILTER works just fine. You might be taking a sledge hammer to a task that is readily accomplished with a normal everyday hammer. Or, a "power tool" when an everyday manual tool works easily. Take your pick of analogies.

best response confirmed by Sithi1984 (New Contributor)
Solution

@Sithi1984 

You may merge the table with itself using Prior Week on left side and Week on right one , like

    #"Merged Queries" = Table.NestedJoin(
        #"Promoted Headers", {"Subscription Code", "Product Category", "Prior Week"},
        #"Promoted Headers", {"Subscription Code", "Product Category", "Week"},
        "Promoted Headers",
        JoinKind.LeftOuter
    ),

Just expand Amount after that and apply desired cosmetic.

Hi @mathetes
FILTER function is not working for me, Can you please help me with some other approach?

@rv3kk 

 

Help you with what? You jumped in on this thread "from the side," so to speak, a thread that had ended half a year ago. And you jumped in without any introduction as to what you're doing.

 

It would be better to start a whole new thread. And I would strongly suggest you consider helping others help you by posting a copy of your spreadsheet, the one where the "FILTER function is not working."