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
Luukvv93
Helper II
Helper II

Need help with a measure: iterating through times

Hi all,

 

I have one fact table (first image) and a dimension time including duration per shift (dag=day and avond=evening).

For each line in the fact table (first image) I want a calculated column that calculates whether the shift is day or evening (based on the shifts in the second image).

 

All help is greatly appreciated

 

 

 

tempsnip.png

 tempsnip.png

 

1 ACCEPTED SOLUTION

@Luukvv93

Sorry, it's missing the VALUES( )

 

WhatShift =
CALCULATE (
    VALUES(DimDate[Shift]),
    FILTER (
        DimDate,
        DimDate[Datum] = FactTable[DatumTijd].[Date]
            && FactTable[DatumTijd] >= DimDate[StartTijd]
            && (
                FactTable[DatumTijd] <= DimDate[EindTijd]
                    || DimDate[EindTijd] = BLANK ()
            )
    )
)

View solution in original post

6 REPLIES 6
AlB
Super User
Super User

@Luukvv93

Try this for your calculated column:

 

WhatShift =
CALCULATE (
    DimDate[Shift],
    FILTER (
        DimDate,
        DimDate[Datum] = FactTable[DatumTijd].[Date]
            && FactTable[DatumTijd] >= DimDate[StartTijd]
            && (
                FactTable[DatumTijd] <= DimDate[EindTijd]
                    || DimDate[EindTijd] = BLANK ()
            )
    )
)

 

I see that there's a blank for one of the [EindTijd] values. The code assumes that's equivalent to the end of the day.   

Hi @AlB,

 

After calculate it's impossible to put DimDate[Shift], any idea how to resolve? Proper connections have been made in the data model so that's not hte issue

@Luukvv93

Sorry, it's missing the VALUES( )

 

WhatShift =
CALCULATE (
    VALUES(DimDate[Shift]),
    FILTER (
        DimDate,
        DimDate[Datum] = FactTable[DatumTijd].[Date]
            && FactTable[DatumTijd] >= DimDate[StartTijd]
            && (
                FactTable[DatumTijd] <= DimDate[EindTijd]
                    || DimDate[EindTijd] = BLANK ()
            )
    )
)

@AlB Will figure it out tomorrow, thanks for the help

AlB
Super User
Super User

Hi @Luukvv93

 

You mean you want to take the Date/Time value in your first table in column 'DatumTijd' and check where that value falls in the second table, i.e.  between what StartTijd and EindTijd and from there determine whether it is Avond or Dag?

@AlB, That's correct!

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.