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

Data model with 2 many to many fact tables

Hello,

 

I'm trying to build a report for employee time stamping, that has worker name, date, and personnelnumber as separate slicers. The report table has Date and several time stamps from the StampJournalTable as rows. I'm trying to include the lunch in/out times from StampJournalTrans in the report table. To achieve this, I'm building 2 calculated columns(Lunch in 2/Lunch out 2) that have data which corresponds the date and personnelnumber in StampJournalTable and have duplicate values. Also in StampJournalTrans both Date and Worker ID have duplicate values since there can be several worker stamps for each date.

 

I've tried to use the following DAX formulas for Lunch out 2 calculated column:

 

Lunch out 2 = LOOKUPVALUE(StampJournalTrans[LUNCH OUT], StampJournalTrans[WORKER ID], RELATED(Worker[WORKER ID]), StampJournalTrans[DATE], StampJournalTable[DATE])

 

Produces the error: "A table of multiple values was supplied where a single value was expected."

 

Lunch out 2 = CALCULATE(
FIRSTNONBLANK(StampJournalTrans[LUNCH OUT],1),
FILTER(StampJournalTrans, StampJournalTrans[DATE]=StampJournalTable[DATE]
&& StampJournalTrans[WORKER ID]=RELATED(Worker[WORKER ID])))

 

Produces wrong values. For example for a date when the worker has not made any other time stamps.

 

I have added a picture of my current data model, which has the keys between tables circled in red. I feel like I'm close to solving this but still can't quite figure it out. Any idea how I should fix my DAX formulas? I hope my explanation of the problem made sense. Thanks for any help.

 

Time&Attendance-Lunch.png

1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @Anonymous 

You may try to create a column like below:

Column =
CALCULATE (
    MAX ( StampJournalTrans[LUNCH OUT] ),
    FILTER (
        StampJournalTrans,
        StampJournalTrans[DATE] = StampJournalTable[DATE]
            && StampJournalTable[personnelnumber] = RELATED ( Worker[Personnelnumber] )
    )
)

Regards,

Community Support Team _ Cherie Chen
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

2 REPLIES 2
v-cherch-msft
Employee
Employee

Hi @Anonymous 

You may try to create a column like below:

Column =
CALCULATE (
    MAX ( StampJournalTrans[LUNCH OUT] ),
    FILTER (
        StampJournalTrans,
        StampJournalTrans[DATE] = StampJournalTable[DATE]
            && StampJournalTable[personnelnumber] = RELATED ( Worker[Personnelnumber] )
    )
)

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

That finally seems to have fixed it. Thank you so much @v-cherch-msft 

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.