Forum Discussion

floressdiego's avatar
floressdiego
Helper I
2 years ago

Lastnonblankvalue help

I have 2 tables, one with the date of the last change in wage of each ID and another with hours by each ID.
                            (dd-mm-yy)

IDWageDate Changed
11001-01-23
11501-10-23
22001-02-23
31501-04-23
42001-05-23
42501-08-23
51001-06-23
51501-10-23

Dimension table.
                                          (dd-mm-yy)

IDHoursDate
516611-09-23
517116-11-23
516527-11-23
317808-08-23
417918-03-23
316202-03-23
216512-02-23
416628-02-23
117911-10-23
116514-07-23
416904-03-23
217412-05-23
216711-02-23
116531-10-23
517206-12-23
116605-07-23
116718-01-23
316523-08-23
416917-06-23
316725-03-23
417821-09-23
517231-10-23
517026-12-23
316910-06-23
116201-02-23
416522-11-23

Fact table.

I wanna get the wage * hours for each ID. But each wage has to be the last one available before or equal the date of the wage (Date Changed).

 

If I take the ID 4 for example, on June, it would be 169*20 = 3380.

If I take the ID 4, on November, it would be 165*25 = 4125.

If I select ID, November and June, it would be 4125+3380 = 7505.

And so on. 

 

I can get the values correctly if I select one ID, but if I need to see every ID together, it seems not to work.

The measure I'm using looks something like this:

 

Wage Value = 


VAR _data = MAX(dCalendario[Data]) 
VAR _dataEfetiva = 

CALCULATE(
    AVERAGEX(Table1, MAX(Table1[Date Change])),
    dCalendario[Data],
    FILTER(
        Table1,
        LASTNONBLANKVALUE(Table1[Date Change], Table1[Date Change] <= _data)
    )
)


RETURN
/*CALCULATE(
    MAX(PSO_TAXA_HISTORICO[DT_EFETIVA]),
    ALL(PSO_TAXA_HISTORICO[DT_EFETIVA])
)*/

CALCULATE(
    SELECTEDVALUE(Table1[Wage]) * SUM(Table2[Hours]),
    Table1[Date Change] = _dataEfetiva
)

 

 

Thanks

1 Reply

  • Since these events are immutable you don't need to use measures.  Calculated columns are sufficient.

     

    You have problems in you Wage Changes table - there are entries in the fact table that precede the first wage change.

     

    This is impacting IDs 3 and 4.  Please correct the Changes table. Pegging the missing values at 10 would give: