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
AsmitaColive
Frequent Visitor

How to get first 4 days' of cumulative data for the last 2 months

I want to calculate Collection on 1st, 2nd, 3rd, and 4th day of every month on a cumulative basis. And Comparing current month's data with the previous one.  An indicative sample of data is given below. Cumulative % is calculated against the Total Invoiced Amount.
I have a Collection Date table, Total Collection Metrics & Cumulative Collection Metrics.
Not able to get the data for the first 4 days of every month.

 

Collection For June'20 and July'20
DateJune'20 CollectionJune'20 CumulativeJune'20 Cumulative %July'20 CollectionJuly'20 CumulativeJuly'20 Cumulative %
1st10,0000010,0000015%11,0000011,0000016%
2nd15,0000025,0000023%20,0000031,0000031%
3rd12,0000037,0000030%12,0000043,0000040%
4th10,0000047,0000040%12,0000055,0000055%
       
       
       
6 REPLIES 6
v-eachen-msft
Community Support
Community Support

Hi @AsmitaColive ,

 

You could refer to this resolved case:

https://community.powerbi.com/t5/Desktop/How-to-do-a-running-Sum-by-group-in-Power-Query/td-p/290123

And you could refer to the following codes in query editor.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY49DsAgCEbvQuLmwI/Wwxi3Dp06tN4/rZoUKAN54eMRagW6O0QgjDjqhzmMTjowuAVosQKf+9z8AjYow2c9KGRw+XJNnzUoihh8lkQRl5/64Z9Oxe04P2eDr98e", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"June'20 Collection" = _t, #"June'20 Cumulative" = _t, #"June'20 Cumulative %" = _t, #"July'20 Collection" = _t, #"July'20 Cumulative" = _t, #"July'20 Cumulative %" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"June'20 Collection", Int64.Type}, {"June'20 Cumulative", Int64.Type}, {"June'20 Cumulative %", Percentage.Type}, {"July'20 Collection", Int64.Type}, {"July'20 Cumulative", Int64.Type}, {"July'20 Cumulative %", Percentage.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Skip(List.Accumulate(#"Changed Type"[#"June'20 Collection"], {0},(cumulative,cost) => cumulative & {List.Last(cumulative) + cost})){Number.FromText(Text.Start([Date],1))-1})
in
    #"Added Custom"

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Greg_Deckler
Super User
Super User

@AsmitaColive - Is that actually how your source data looks? 1st, 2nd, 3rd, 4th in the Date column and not actual dates? If that is the case, use LEFT([Date],2) to extract the first two characters. Get rid of any column ending in a zero. The get the first character LEFT([Date],1) and then you can make this column numeric and filter out anything >4 and then do a running total across this table. Or, use actual dates and skip the misery.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the reply.  1st 2nd ...are actual dates...like I want to see this month's 1st to 4th collection and last month's 1to 4th collection...

@AsmitaColive - OK, if they are actual dates, that makes things much easier. You can just do a running/cumulative total by using something like:

SUMX(FILTER('Table',[Date] <= EARLIER('Table'[Date]),[Column])

 

To be more specific, would have to know how your source data is organized. 
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


Also, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I would like to share the sample data. 
Have performed a few calculations but not getting the desired result. I think I have to learn more about Date Hierarchy 

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