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

Days in Quarter (custom colomn)

Hello,

 

I want to extract the days in a quarter from 2 dates.

Is this possible? .

 

Example:

Start date 1-1-2019 

End date 31-12-2019

 

days Quarter 1, days quarter 2, days quarter3, days quarter 4

 

Or 

 

Start date 1-3-2019 

End date 31-7-2019

days Quarter 1, days quarter 2, days quarter3, days quarter 4

1 ACCEPTED SOLUTION
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

I created  sample table as below:

1.png

Then create 2 parameters as Start and End:

2.png

Add new blank query with below M code to count the days in each quarter :

Days Qtr 1:
let
    Source = List.Dates( Start, Number.From( End - Start) +1, #duration(1,0,0,0)),
    Custom1 = List.Select(Source, each Date.QuarterOfYear(_)=1),
    #"Calculated Count" = List.NonNullCount(Custom1)
in
#"Calculated Count"


Days Qtr 2:
let
    Source = List.Dates( Start, Number.From( End - Start) +1, #duration(1,0,0,0)),
    Custom1 = List.Select(Source, each Date.QuarterOfYear(_)=2),
    #"Calculated Count" = List.NonNullCount(Custom1)
in
#"Calculated Count"


Days Qtr 3:
let
    Source = List.Dates( Start, Number.From( End - Start) +1, #duration(1,0,0,0)),
    Custom1 = List.Select(Source, each Date.QuarterOfYear(_)=3),
    #"Calculated Count" = List.NonNullCount(Custom1)
in
#"Calculated Count"


Days Qtr 4:
let
    Source = List.Dates( Start, Number.From( End - Start) +1, #duration(1,0,0,0)),
    Custom1 = List.Select(Source, each Date.QuarterOfYear(_)=4),
    #"Calculated Count" = List.NonNullCount(Custom1)
in
#"Calculated Count"

Right click each query to create the function:

3.png

4.png

Finally , invoke custome function in fact table:

5.png

6.png

7.pngThe results shown as below:

7.png

Best regards,

Dina Ye

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

View solution in original post

3 REPLIES 3
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

I created  sample table as below:

1.png

Then create 2 parameters as Start and End:

2.png

Add new blank query with below M code to count the days in each quarter :

Days Qtr 1:
let
    Source = List.Dates( Start, Number.From( End - Start) +1, #duration(1,0,0,0)),
    Custom1 = List.Select(Source, each Date.QuarterOfYear(_)=1),
    #"Calculated Count" = List.NonNullCount(Custom1)
in
#"Calculated Count"


Days Qtr 2:
let
    Source = List.Dates( Start, Number.From( End - Start) +1, #duration(1,0,0,0)),
    Custom1 = List.Select(Source, each Date.QuarterOfYear(_)=2),
    #"Calculated Count" = List.NonNullCount(Custom1)
in
#"Calculated Count"


Days Qtr 3:
let
    Source = List.Dates( Start, Number.From( End - Start) +1, #duration(1,0,0,0)),
    Custom1 = List.Select(Source, each Date.QuarterOfYear(_)=3),
    #"Calculated Count" = List.NonNullCount(Custom1)
in
#"Calculated Count"


Days Qtr 4:
let
    Source = List.Dates( Start, Number.From( End - Start) +1, #duration(1,0,0,0)),
    Custom1 = List.Select(Source, each Date.QuarterOfYear(_)=4),
    #"Calculated Count" = List.NonNullCount(Custom1)
in
#"Calculated Count"

Right click each query to create the function:

3.png

4.png

Finally , invoke custome function in fact table:

5.png

6.png

7.pngThe results shown as below:

7.png

Best regards,

Dina Ye

Community Support Team _ Dina Ye
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-diye-msft Wow no wonder i could no do it. its huge!

I am going to proces this in Power BI. it can take a will but i will respond.

 

Thank you in adance

Anonymous
Not applicable

Wonderfull! it works. i just hav eto make some addjustmenst in cause there are null values.

the cell retruns an error.

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.