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
swaink
Regular Visitor

Count occurencies of one column if the week number in another column is the latest week no

Dear All

 

I am new to Powewr BI but I am truly enjoying what it is able to do fo rme

 

I have however hit a snag and am struggling with getting my head around a solution

 

In one column I have "Service Type" and in another column I have the week numbers

 

I am trying to create a measure that counts the number of occurencies of the "Service Type" if the Week number column is showing the latest week number (I.E the maximum week number in the column)  

 

Unfortunately I have hit a wall and can't see the solution would anyon ebe able to advise me please

 

Regards

 

Kevin

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Given this Enter Data query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk4tKstMTlUwVNJRMjZRitUhKGRohCJkhKkKLGSMImQMFYoFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Service = _t, WeekNum = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Service", type text}, {"WeekNum", Int64.Type}})
in
    #"Changed Type"

Create these measures:

 

MAXWeekNum = CALCULATE(MAX(Services[WeekNum]),ALL(Services))

CountWeekNum = COUNT(Services[WeekNum])

CountCurrentWeekNum = CALCULATE([CountWeekNum],FILTER(Services,Services[WeekNum] = [MAXWeekNum]))

@ 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...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

Given this Enter Data query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk4tKstMTlUwVNJRMjZRitUhKGRohCJkhKkKLGSMImQMFYoFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Service = _t, WeekNum = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Service", type text}, {"WeekNum", Int64.Type}})
in
    #"Changed Type"

Create these measures:

 

MAXWeekNum = CALCULATE(MAX(Services[WeekNum]),ALL(Services))

CountWeekNum = COUNT(Services[WeekNum])

CountCurrentWeekNum = CALCULATE([CountWeekNum],FILTER(Services,Services[WeekNum] = [MAXWeekNum]))

@ 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...

Hi smoupre

 

Thank you for the swift reply it is appreciated

 

I have applied the measures as you suggested and that has indeed solved my problem thank you

 

Kevin

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.