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
Mars3442
Helper I
Helper I

Filtering data only last week of the month

Hi All,

 

I have stock data

DateStock
2 Jan 20231000
1 Feb 20232000
1 March 20234000
10 April 2023300
17 April 2023200
24 April 2023400
31 April 2023500
14 May 2023400
22 May 2023200
29 May 2023500

 

But I only need 1 data per month. If 1 month only has 1 data, show it. But if 1 month has more than 1 data, show the last week's data of that month

 

Expected result

DateStock
2 Jan 20231000
1 Feb 20232000
1 March 20234000
31 April 2023500
29 May 2023500

 

Please help me find Dax in Power BI or I can filter the data in Power Query

 

 

2 REPLIES 2
ThxAlot
Super User
Super User

Both ways are easy enough,

 

DAX

ThxAlot_0-1697182052045.png

 

PQ

 

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

    Grouped = Table.FromRecords(Table.Group(#"Changed Type", "Date", {"grp", Table.Last}, 0, (x,y) => Byte.From(Date.Month(x)<>Date.Month(y)))[grp])
in
    Grouped

 

 

 

ThxAlot_0-1697181128489.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



vibhormittal93
New Member

Hi @Mars3442 ,

This problem is solved in one of the past discussions here

You can either filter the data in power query or create a calculated column to filter only the desired rows. Unfortunately, there won't be any easy way to filter rows via DAX.


I would suggest to add a calculated column to your table as suggested by Shishir.

Flag = 
VAR _MaxDate =
    CALCULATE (
        MAX ( 'Data'[Date] ),
        FILTER (
            'Data',
                 'Data'[Year] = EARLIER ( 'Data'[Year] )
                && 'Data'[Month] = EARLIER ( 'Data'[Month] )
        )
    )
RETURN
    IF ( _MaxDate = 'Data'[Date], 1, BLANK () )

 

vibhormittal93_0-1697180143781.png


Please mark it as answer if it resolves your issue. Kudos are also appreciated.

Regards
Vibhor

 

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.