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

Selected only the last week of each month

Hi , I have a column : yearmonthweek, for example 20220414 (2022-04 and week 14).

I want to split this column into 3 and create a measure that returns the last week of each month. 

For example 20220417 => "last week of April" etc...

 

Thank you

1 ACCEPTED SOLUTION
BeaBF
Impactful Individual
Impactful Individual

@Anonymous ok, so you can do:

  • Group by in the Power Query, to extract the max week corresponding to each Year-Month:
    #"Raggruppate righe" = Table.Group(#"Modificato tipo", {"Year", "Month"}, {{"Week", each List.Max([Week]), type nullable number}})
    in
    #"Raggruppate righe"
  • You can do it directly in the viz by adding the maximum of week:
    BeaBF_0-1649758503723.png
  • Last, create a measure like this:
    Misura = CALCULATE(MAX(Tabella[Week]), ALLEXCEPT(Tabella, Tabella[Year], Tabella[Month]))
     
    Tell me if there is something unclear, I hope it can help you!
    BF.

View solution in original post

7 REPLIES 7
v-rongtiep-msft
Community Support
Community Support

Hi @Anonymous , 

Please refer to my pbix file to see if it helps you.

Create a measure.

Measure =
VAR _maxweek =
    CALCULATE (
        MAX ( 'Table'[week] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Year] = SELECTEDVALUE ( 'Table'[Year] )
                && 'Table'[Month] = SELECTEDVALUE ( 'Table'[Month] )
        )
    )
RETURN
    IF ( MAX ( 'Table'[week] ) = _maxweek, 1, BLANK () )

vpollymsft_0-1649999818416.png

If I have misunderstood your meaning, please provide your pbix file without privacy information and your desired output.

 

Best Regards

Community Support Team _ Polly

 

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

 

Anonymous
Not applicable

@v-rongtiep-msft thank you for your answer 😉

BeaBF
Impactful Individual
Impactful Individual

@Anonymous Hi!

Can you paste some sample data and the expected result in explicit way?

 

Thx,

BF.

Anonymous
Not applicable

@BeaBF  I have 3 columns: Year, Month, Week 

I want to return the last week of each months. 

For example : Year = 2022 , Month = 04  and Week of april = 13,14,15,16,17

I want to return 04-17

 

BeaBF
Impactful Individual
Impactful Individual

@Anonymous You have data in this way? 

BeaBF_0-1649757403675.png

 

BF

Anonymous
Not applicable

Yes ! @BeaBF 

BeaBF
Impactful Individual
Impactful Individual

@Anonymous ok, so you can do:

  • Group by in the Power Query, to extract the max week corresponding to each Year-Month:
    #"Raggruppate righe" = Table.Group(#"Modificato tipo", {"Year", "Month"}, {{"Week", each List.Max([Week]), type nullable number}})
    in
    #"Raggruppate righe"
  • You can do it directly in the viz by adding the maximum of week:
    BeaBF_0-1649758503723.png
  • Last, create a measure like this:
    Misura = CALCULATE(MAX(Tabella[Week]), ALLEXCEPT(Tabella, Tabella[Year], Tabella[Month]))
     
    Tell me if there is something unclear, I hope it can help you!
    BF.

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