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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Durbslaw
Helper I
Helper I

Summarize from multiple tables

CountNewHires1.PNGHello Forum,

 

TIA for reading and responding, I am using SSAS as a source, and have created this measure to calculate month difference between 2 dates

New Hires Month Datediff =
IF (
MAX('MovementSnapshot'[AppointmentDateKey]) <> BLANK ()
&& MAX('MovementSnapshot'[AppointmentDateKey]) <> -1,
VAR CurrentMovement =
MAX ( 'MovementSnapshot'[AppointmentDateKey] )
VAR CurrentPeriod =
MAX ( 'Period'[YearMonth] )
VAR MovementYear =
VALUE ( LEFT ( CurrentMovement, 4 ) )
VAR MovementMonth =
VALUE ( MID ( CurrentMovement, 5, 2 ) )
VAR PeriodYear =
VALUE ( LEFT ( CurrentPeriod, 4 ) )
VAR PeriodMonth =
VALUE ( RIGHT ( CurrentPeriod, 2 ) )
RETURN
( PeriodYear - MovementYear ) * 12 + PeriodMonth - MovementMonth
)

The issue comes when I am trying to count the number of 0 and 1 month occurrences.

CountNewHires =
COUNTROWS(
FILTER(
SUMMARIZE(
'Period',
'Period'[Yearmonth],
RelatedTable(''MovementSnapshot'[AppointmentDateKey]),
"Value" , [New Hires Month Datediff]
),
[Value] = 0 || [Value] = 1
))

 

The syntax error is attached.CountNewHires.PNG

2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @Durbslaw 

please use the following 

New Hires Month Datediff =
VAR CurrentMovement =
    MAX ( 'MovementSnapshot'[AppointmentDateKey] )
RETURN
    IF (
        CurrentMovement <> BLANK ()
            && CurrentMovement <> -1,
        VAR CurrentPeriod =
            MAX ( 'Period'[YearMonth] )
        VAR MovementYear =
            VALUE ( LEFT ( CurrentMovement, 4 ) )
        VAR MovementMonth =
            VALUE ( MID ( CurrentMovement, 5, 2 ) )
        VAR PeriodYear =
            VALUE ( LEFT ( CurrentPeriod, 4 ) )
        VAR PeriodMonth =
            VALUE ( RIGHT ( CurrentPeriod, 2 ) )
        RETURN
            ( PeriodYear - MovementYear ) * 12 + PeriodMonth - MovementMonth
    )
CountNewHires =
COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( 'MovementSnapshot', 'Period'[Yearmonth] ),
            "Value", [New Hires Month Datediff]
        ),
        [Value] = 0
            || [Value] = 1
    )
)

 

View solution in original post

@Durbslaw 
I think this is the time when you need to add some columns and create a relatioship between the two tables.

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Durbslaw 

please use the following 

New Hires Month Datediff =
VAR CurrentMovement =
    MAX ( 'MovementSnapshot'[AppointmentDateKey] )
RETURN
    IF (
        CurrentMovement <> BLANK ()
            && CurrentMovement <> -1,
        VAR CurrentPeriod =
            MAX ( 'Period'[YearMonth] )
        VAR MovementYear =
            VALUE ( LEFT ( CurrentMovement, 4 ) )
        VAR MovementMonth =
            VALUE ( MID ( CurrentMovement, 5, 2 ) )
        VAR PeriodYear =
            VALUE ( LEFT ( CurrentPeriod, 4 ) )
        VAR PeriodMonth =
            VALUE ( RIGHT ( CurrentPeriod, 2 ) )
        RETURN
            ( PeriodYear - MovementYear ) * 12 + PeriodMonth - MovementMonth
    )
CountNewHires =
COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( 'MovementSnapshot', 'Period'[Yearmonth] ),
            "Value", [New Hires Month Datediff]
        ),
        [Value] = 0
            || [Value] = 1
    )
)

 

@tamerj1  Thank you very much however still getting..

syntax error 3.PNG

@Durbslaw 
I think this is the time when you need to add some columns and create a relatioship between the two tables.

Durbslaw
Helper I
Helper I

I have also tried...

CountNewHires =
COUNTROWS(
FILTER(
SUMMARIZE(
'Period',
'Period'[Yearmonth],
'MovementSnapshot'[AppointmentDateKey],
CALCULATETABLE ( VALUES ('Staff Management' [New Hires Month Datediff] ) )
),
[Value] = 0 || [Value] = 1
))

AND

CountNewHires =
COUNTROWS(
FILTER(
SUMMARIZE(
'Period',
'Period'[Yearmonth],
CALCULATETABLE ('MovementSnapshot'[AppointmentDateKey],
Value , [New Hires Month Datediff]
),
[Value] = 0 || [Value] = 1
))

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.