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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mlsx4
Super User
Super User

Problem with granularity

Hello everyone!

 

I have a problem that I cannot figure out how to solve. 

Let's say I need to compute the difference between my theoretical rate and my real rate. Therefore I have a table for my theoretical rate:

 

*Notice that I have different categories, different centers (11, 12, 13) but also companies (A, B).

CodTheoretical rateCategoryYearMonth
11A8,73A2023-Junio
11A18,08B2023-Junio
11A2,62C2023-Junio
12A2,62A2023-Junio
12A0,38B2023-Junio
12A1C2023-Junio
11B2,62A2023-Junio
11B0,5B2023-Junio
11B0,5C2023-Junio

 

This theoretical rate should keep for next months/ years until there is some change in the value (could be a year later, in a month,... There is no defined change time).

 

My problem is that I don't know how to compute the difference using the currently active value. For instance, if I am in August these values are still effective. However, and because of the YearMonth it is only computed for June.

All of these, being aware of the corresponding center / company...

14 REPLIES 14
sergej_og
Super User
Super User

Hi @mlsx4 ,
I tried different approaches for this case..and hope I catched it right concersing your discription.
I had to tweek a bit with model and measures.

Actually I get following result:

sergej_og_1-1692797016325.png

 - Assuming real rate data comes daily and theretical rate data random -> Real Rate table is my Fact table
 - LookUp for theoretical rates (calculated column)
 - works for each single Code (conserning your Screen above)
-----------------------------------------
Is this about the expected result?

Regards

Hi @sergej_og 

 

That's what I need!! How can I achieve it?

Hey @mlsx4 ,
glad to hear.
I will try to leave you an understandable description here.
-------------------------------------------------
1. I created a calculated column in "real rate" table (my fact table) to fetch theoretical rates.
Result:

sergej_og_0-1693496893668.png

Formula:

LookUp_Theo_rate = 
   LOOKUPVALUE(
      'Theo rate Table'[Theor. Rate], 'Theo rate Table'[YearMonth], 'REAL rate Table'[YearMonth],
      'Theo rate Table'[Code], 'REAL rate Table'[Code],
      'Theo rate Table'[Category], 'REAL rate Table'[Category])

 
Can you pls try to achieve similar result.


When I drop these 2 fields into my table it looks like this:

sergej_og_1-1693497545402.png

 

2. To fill the gaps I used this formula:

Last non blank Theo_rate = 
VAR Last_non_blank_date = 
        CALCULATE(
            MAX('REAL rate Table'[YearMonth]),
            FILTER(
                ALL('REAL rate Table'), 'REAL rate Table'[YearMonth] <= MAX('REAL rate 
                Table'[YearMonth]) && 'REAL rate Table'[LookUp_Theo_rate] <> BLANK() )
            )    //this part will give you the MAX non blank date

VAR Last_non_blank_Value =
        CALCULATE(
            SUM('REAL rate Table'[LookUp_Theo_rate]),
            FILTER(
                ALL('REAL rate Table'), 'REAL rate Table'[YearMonth] = Last_non_blank_date), 
            FILTER(
                ALL('REAL rate Table'), 'REAL rate Table'[Code] = SELECTEDVALUE('REAL rate Table'[Code])),
            'REAL rate Table'[Category] = SELECTEDVALUE('REAL rate Table'[Category])
            )

RETURN
    IF(
        HASONEVALUE('Calendar'[Date]) &&
        [Theor_] <> BLANK(),
        [Theor_],
        Last_non_blank_Value)

Try to apply this piece of code into your model.
I cross my fingers.

I hope I could transfer this well to your case.
This formula gave me this result:

sergej_og_2-1693498287349.png
----------------------------
Regards

Hi @sergej_og 

 

Thank you. You have explained perfectly. I will try, because Real Rate is not a table... It is calculated 😪 The calculus is a real headache

Maybe you can show a bit more of your data model or describe your case (especially the part with real rate) a bit more.
How do you get your real rates into your model?

Hi @sergej_og 

 

I'm gonna try to explain it:

  • I have a dim table for centers with codes, location, full name...
  • I have a fact table with all temporary medical leaves and absences due to holidays, marriages, or some any other reason
  • I have a dim table with all the staff
  • Finally, I have a calendar table

Then:

Sample of absences table would be:

Type of absenceSubtype of absenceEmployee CodeEmployee ID

Employee

Name

Starting dateEnding dateCenter Key
AbsenceHolidays00000198765431AJuan López01/06/202307/06/202311A
Medical leaveAccident00001543275618YDavid Fernández08/06/2023 11A
AbsenceMarriage00000212345679BMaría Martínez04/06/202319/06/202311A

 

Sample of Staff table will be:

Employee CodeFull nameWorking CategoryContract category

Employee

% of hours

Starting dateEnding dateCenter Key
000001Juan LópezAFull time10007/05/2017 11A
000002María MartínezB

Temporary

7501/06/202325/06/202311A
000015David FernándezCPartial-time89,7401/05/202331/12/202311A

 

 

So, with all this information what I'm doing to calculate the rate of people is:

  • First, I compute if a person is on holidays or in a medical leave. Put a 0 if it is, or a 1 if not.
  • Then, I compute if a person has an active contract. Put a 0 if it isn't or a 1 if it is active.
  • I use both measures as a multiplier: employees rate * isOnHoliday* isActive, where employee rate is %hours/100
  • Then, I summarized by the day

So, for instance Juan will have 0 for days between 1 and 7 of June, while for the rest of the month will give me a rate of 1. María will have 0,75 for days 1 to 3 and 20 to 25. 0 for all the rest. And so on...

 

Hope it is a little more clear now

@mlsx4 
ok, that´s a bit different starting point.
Can you post your calculations for computing "on holidays etc.", "is active etc.".
I will try to reconstruct and understand this.

Maybe a calculated table could be a possible solution.

My measures are a bit mess, because I have tried several ways to do it. This way works for all the graphs I need to show (except the theoretical one), but they are not probably the optimum way of doing or even I'm spinning around in circles:

BajasD = 
    CALCULATE(DISTINCTCOUNT('IT/ABS'[Employee name]),
    FILTER('IT/ABS','IT/ABS'[Starting date]<=MAX('Calendar'[Date]) && OR('IT/ABS'[Ending date] >=MAX('Calendar'[Date]),ISBLANK('IT/ABS'[Ending date]))))
//The multiplier
Multiplicador de bajas = IF([BajasD]=1,0,1)

 

For active contract:

DiaT = CALCULATE(
    SUMX(VALUES('Calendar'[Date]),CALCULATE(DISTINCTCOUNT('Plantilla'[Employee code]),
    FILTER('Plantilla','Plantilla'[Starting date]<=MAX('Calendar'[Date])&& 'Plantilla'[Ending date]>=MAX('Calendar'[Date])))))
//The multiplier
Multiplicador de jornada = IF([DiaT]=1,1,0)

 

Ratio jornada = 

VAR diasMes= DAY(LASTDATE('Calendar'[Date]))

var num= SUMX(VALUES('Plantilla'[Employee Code]),CALCULATE(SUMX('Plantilla','Plantilla'[% Jornada]),FILTER('Plantilla','Plantilla'[Starting date]<=MAX('Calendar'[Date]))))

RETURN num* CALCULATE([Multiplicador de bajas],USERELATIONSHIP(Employee code],'IT/ABS'[Employee code]))*[Multiplicador de jornada] 

 

Ratio totales = 

var summarizedTable = ADDCOLUMNS (
SUMMARIZE ( 'Plantilla', 'Plantilla'[Employee code],'Plantilla'[% Jornada]),
"Días", CALCULATE ([Ratio jornada]) )

RETURN SUMX(summarizedTable,[Ratio jornada])

 

sergej_og
Super User
Super User

Hey @mlsx4 ,
not sure since I have no clue how your datamodel looks like.
Show me your table with your theoretical values before and after change of values.
I don´t know how your data come in/stored in the table.
Do you have a new line for new values or is the value overwritten?

Hi @sergej_og 

 

Theoretical rates are defined in a table by just including a new line and the date they have been changed. That's why I said that it's being a headache.

 

Following the example, this would be theoretical rates table. For instance, in Jun-2023, category A changes its value:

CenterKeyCategoryTheoretical rate

Date

11AA8,73

Jun-2022

11AB18,08

Jun-2022

11AC2,62

Jun-2022

11AA9

Jun-2023

 

Thank you so much for your effort 😊

sergej_og
Super User
Super User

Hey @mlsx4 ,
something like this?

sergej_og_0-1692656507264.png

I made a small model following data your provided above (expected output).
Would it work for you.

Regards

Yes, but with a small detail, imagine that on 09/06 theoretical rate changes... Would it work for the new rates?

sergej_og
Super User
Super User

Do you have a target result which you can provide here?
Difficult to understand just seeing at your Screenshot and a bit discription.
What is your expected goal?

Hi @sergej_og 

 

This is my expected output. Imagine the top part are the slicers options.

 

mlsx4_0-1692618771327.png

 

If I do things just for a center (no selectors) I can achieve it without any problem. The thing is that I have all centers in the same file (coded as 11A,11B, 12A...) and the date handicap, since theoretical rates can change from one month to another. 

Also, as you can see granularity in the output is daily, but I only have theoretical rates within a date (the one in which is established).

 

It has been a headache for myself try to solve it. 

Thank you for trying to help.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.