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
SudhanshuB
New Member

Date Filter

Hello, 
I have requirement where I want to fetch the count of the values in each quarter as "Due in Current Quarter" . For exmaple , Please consider the below table :

NameDate of Birth
Tom1st Jan 24
Harry 4th Mar 24
Nick29th May 24

In the above table , whoesver Date of Birth is passed with respect to current date/today's date within the current quarter , the count should not include them . Let say for Q1, the count should be 1 as 1st Jan 24 is in past and 29th May 24 is in Q2. Similarly, For Q2 the count should be 1 for "Due in current quarter". 

Please suggest . 

5 REPLIES 5
dufoq3
Super User
Super User

Hi @SudhanshuB,

 

Source:

dufoq3_1-1706884867407.png

 

Result:

dufoq3_0-1706884811871.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsnPVdJRMiwuUfBKzFMwMlGK1YlW8kgsKqpUAIqblGQo+CYWwcT9MpOzgaJGlmDhSrBwLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Date of Birth" = _t]),
    TransformedDate = Table.TransformColumns(Source, {{"Date of Birth", each Text.Combine(List.Transform(Text.Split(_, " "), (a)=>
     List.Accumulate(
         List.Buffer({"st", "nd", "rd", "th"}),
         a,
         (s,c)=> Text.Replace(Text.Trim(s), c, "") )), " "), type text }}),
    TransformedDateType = Table.TransformColumns(TransformedDate, {{"Date of Birth", each Date.FromText(_, [Format="%d MMM yy", Culture="en-US"]), type date}}),
    Ad_CurrentYear = Table.AddColumn(TransformedDateType, "Current Year", each Date.Year(DateTime.LocalNow()), Int64.Type),
    Ad_YearQuarters = List.Accumulate(
    List.Buffer({1..4}),
    Ad_CurrentYear,
    (s,c)=> Table.AddColumn(s, "Q"& Text.From(c) & "-" & Text.From(Date.Year(DateTime.LocalNow())), each 
               if not ([Date of Birth] < Date.From(DateTime.LocalNow()))
               and Date.Year([Date of Birth]) = Date.Year(DateTime.LocalNow())
               and Date.QuarterOfYear([Date of Birth]) = c then 1 else 0, Int64.Type) ),
    GroupedRows = Table.Group(Ad_YearQuarters, {"Current Year"}, {{"Detail", each _, type table},
     {"Q1-" & Text.From(Date.Year(DateTime.LocalNow())), each List.Sum(Table.ToColumns(Table.SelectColumns(_, {"Q1-" & Text.From(Date.Year(DateTime.LocalNow()))})){0}), Int64.Type},
     {"Q2-" & Text.From(Date.Year(DateTime.LocalNow())), each List.Sum(Table.ToColumns(Table.SelectColumns(_, {"Q2-" & Text.From(Date.Year(DateTime.LocalNow()))})){0}), Int64.Type},
     {"Q3-" & Text.From(Date.Year(DateTime.LocalNow())), each List.Sum(Table.ToColumns(Table.SelectColumns(_, {"Q3-" & Text.From(Date.Year(DateTime.LocalNow()))})){0}), Int64.Type},
     {"Q4-" & Text.From(Date.Year(DateTime.LocalNow())), each List.Sum(Table.ToColumns(Table.SelectColumns(_, {"Q4-" & Text.From(Date.Year(DateTime.LocalNow()))})){0}), Int64.Type}
})
in
    GroupedRows

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

CidcleyBarbosa
Advocate IV
Advocate IV

Hi @SudhanshuB 
This is one way of doing it:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsnPVdJRMiwuUfBKzFMwMlGK1YlW8kgsKqpUAIqblGQo+CYWwcT9MpOzgaJGlmDhSrBwLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Date of Birth" = _t]),
    #"Changed Type" = Table.TransformColumns(Source, {{"Date of Birth", each Date.From(DateTimeZone.From(Text.Select(Text.BeforeDelimiter(_, " "), {"0".."9"}) & " " & Text.BetweenDelimiters(_, " ", " ") & " " & Text.End(_, 2))), type date}}),
    #"Added Date Filter" = Table.AddColumn(#"Changed Type", "Date Filter", each if [Date of Birth] < DateTime.Date(DateTime.LocalNow()) then "Past date" else if [Date of Birth] >= Date.StartOfQuarter(DateTime.Date(DateTime.LocalNow())) and [Date of Birth] <= Date.EndOfQuarter(DateTime.Date(DateTime.LocalNow())) then "Due in current quarter" else "Due in " & Text.Combine({Date.ToText([Date of Birth], "yy"), "Q", Text.From(Date.QuarterOfYear([Date of Birth]), "en-US")}), type text)
in
    #"Added Date Filter"

The result:

CidcleyBarbosa_0-1706878537713.png

Best regards,
Cidcley Barbosa

Thanks ! Its really complicated . Could you help me with a simplified DAX query . Let me reiterate my question again :
I have a requirement where I need the data which are due in current quarter . For example ,

AIIDApplication Name Next DR Scheduled
12345X27th Jan 24
43276Y02nd Mar 24
86531Z8th Mar 24
78856W28th Feb 24


Here in the above table it shows the DR date for X is already completed . Now we are in month of February 24 and we have 3 more DRs to be performed . Hence, If someone asks how many DRs are due for current month , it should be 3 . So, I need to dynamically either have a date filter applied or add a measure to achieve . 

 

Please suggest .

Thanks ! Its really complicated . Could you help me with a simplified DAX query . Let me reiterate my question again :
I have a requirement where I need the data which are due in current quarter . For example ,

AIIDApplication Name Next DR Scheduled
12345X27th Jan 24
43276Y02nd Mar 24
86531Z8th Mar 24
78856W28th Feb 24


Here in the above table it shows the DR date for X is already completed . Now we are in month of February 24 and we have 3 more DRs to be performed . Hence, If someone asks how many DRs are due for current month , it should be 3 . So, I need to dynamically either have a date filter applied or add a measure to achieve . 

 

Please suggest .

You can add the  'Date Filter' column in a slicer, select 'Due in current quarter' and, in a visual, add a measure with a simple COUNT. 

CidcleyBarbosa_0-1707418634065.png

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