Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Spazia
Frequent Visitor

Start/End Date %Calculation by quarter

Hello,

 

I have a calendar table and the following data:

CheckNbrKeyResultStart DateEnd DateIndexCheckNbr_Key
1A1

01/01/2020

31/05/202011A
2A001/01/202008/05/202022A
3A001/01/202024/02/202033A
4A001/01/202008/05/202044A
5A001/01/202031/12/999955A
6A101/01/202031/12/999966A
2A109/05/202031/12/999972A
3A125/02/202031/12/999983A
4A109/05/202031/12/999994A

 

I would like to calculate over time the nbr of 1 compare to the total of rows. I used this formula:

% Quality = 

VAR _FirstDate = FIRSTDATE ( 'Calendar'[Date] )

VAR _LastDate = LASTDATE ( 'Calendar'[Date] )

RETURN

CALCULATE (

DISTINCTCOUNT ( Table[Index] ),

Table[Start Date] <= _LastDate,

Table[EndDate] >= _FirstDate,

Table[Result]=1
)/

CALCULATE (

DISTINCTCOUNT ( Table[Index] ),

Table[Start Date] <= _LastDate,

Table[EndDate] >= _FirstDate
)

 This is working perfectly when in my chart in the x-Axis I have the date. But as soon as I want to put the quarter on the x-Axis the value aren't correct. 
If I put the Quarter in x-Axis I obtain: Quarter 1 = 42.86% and Quarter 2=62.50%

I'm expecting to have Quarter 1 = 50% and Quarter 2=83.3%. Because if a Check_nbr_Key appear twice in the same Quarter, only the one with the latest End Date should be kept.

 

In order to take into account that last parameter I tried this, but it didn't work:

VAR _FirstDate = FIRSTDATE ( 'Calendar'[Date] )

VAR _LastDate = LASTDATE ( 'Calendar'[Date] )

VAR MaxDate = CALCULATE (

MAX ( Table[EndDate] ),

Table[Start Date] <= _LastDate,

Table[EndDate] >= _FirstDate,


)

RETURN

CALCULATE (

DISTINCTCOUNT ( Table[Index] ),
Table[Start Date] <= _LastDate,
Table[EndDate] >= _FirstDate ,
Table[Result]=1,
Table[EndDate] = MaxDate

)/

CALCULATE (

DISTINCTCOUNT ( Table[Index] ),

Table[Start Date] <= _LastDate,
Table[EndDate] >= _FirstDate,
Table[EndDate] = MaxDate

)

 

Does anyone has an idea how I could, keep the one with the latest End Date?

I know that if I create a new table that calculates all the date between start and end date like in this post: Here

But doing that would be performance consuming, and this table will fastly reach millions of rows.

 

2 REPLIES 2

Hello @amitchandak ,

 

Unfortunatelly, what's explained in the link is very close to what I'm doing.

 

However, I found a work around by creating, in my calendar table, a column displaying the quarter only on the last date of the quarter. This avoid to have several rows for the same quarter and have confusion in the %calculation as it'll take the last date.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.