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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
BIDeveloper_
Frequent Visitor

Cumulative count only if value appear one by another

Hello,

 

I have a problem with some calculated column...

I would like to acheive CUMULATIVE count value but when previous group was different then start counting from the begining.

Expected Value:

GROUPEXPECTED VALUEINDEX
A11
A22
B13
B24
B35
C16
A17
A28

 

Right now it is like that:

GROUP    VALUE    INDEX
A11
A22
B13
B24
B35
C16
A37
A48

 

My DAX measure:

CALCULATE  ( COUNT(GROUP),
FILTER(ALL(TABLE),
GROUP = EARILER(GROUP),
INDEX <= EARLIER(INDEX)

)

 

Any advice will be very helpful for me!

Thanks

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

I can assure you that it requires recursive processing, so that the measure, if exists, is far beyond comprehension for normal users like you or me.

 

My solution evolves a helper column,

Screenshot 2021-06-04 195403.pngScreenshot 2021-06-04 194646.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!

View solution in original post

6 REPLIES 6
CNENFRNL
Community Champion
Community Champion

I can assure you that it requires recursive processing, so that the measure, if exists, is far beyond comprehension for normal users like you or me.

 

My solution evolves a helper column,

Screenshot 2021-06-04 195403.pngScreenshot 2021-06-04 194646.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!

hmm... more than 150 views at that time, but no one pointed out such simple logic...

Screenshot 2021-11-07 210136.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!

This is what I was looking for!

THANK YOU SO MUCH  @CNENFRNL !!

You're welcome!

 

Just for fun, here's a solution with Excel formula, our oldie but goodie

Count.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!

Fowmy
Super User
Super User

@BIDeveloper_ 

How about a Power Query approach? Past this code on a New Query in the Advanced Edior and check the steps:

Fowmy_0-1622810018747.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWBsIzALCcgyxjOMoGzTMEsZyDLDK7DHM6yUIqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [GROUP = _t, #"    INDEX" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"GROUP", type text}, {"    INDEX", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"GROUP"}, {{"All", each _, type table [GROUP=nullable text, #"    INDEX"=nullable number]}, {"Count", each Table.RowCount(_), Int64.Type}},GroupKind.Local),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Value", each {1..[Count]}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"All", "Count"}),
    #"Added Index" = Table.AddIndexColumn(#"Removed Columns", "Index", 1, 1, Int64.Type)
in
    #"Added Index"

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Really thank you but unfortunatelly I have to make it with DAX because my "GROUP" column is a calculated column etc...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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