Forum Discussion

srk_powerbi's avatar
srk_powerbi
Helper II
5 years ago
Solved

Calculation help needed

Hi ,

i need osme help calculating a measure.

i have below 2 tables. Both are related by AccountNum coulumn.  I need to calculate Measures for

1. calculate the Count(AccountNum) where RegisteredDate=  Today

2. calculate the Count(AccountNum) where RegisteredDate=  Previous Businessday

3. Calculate the SUM(Amount) where RegisteredDate=  Today

4. Calculate the SUM(Amount) where RegisteredDate=  Previous Businessday

 

Please help.  I dont see option to attach pbix here.

table 1

 

AccountNumNameRegisteredDateCompletedDate
470093594Jeff11/28/202012/1/2020
470101606Vicky11/30/202011/30/2020
470107112Kevin12/3/2020NULL
470099664Peter12/1/202012/2/2020
720109049Victor11/25/2020NULL
470108423Rachel11/24/202011/30/2020
470104785Ian12/3/2020NULL
470109222Nicky12/2/202012/3/2020
720108958Carl11/29/202012/1/2020

 

table 2

AccountNum Amount 
470093594 $                               2,000.00
470101606 $                               3,500.00
470107112 $                                  800.00
470099664 $                               2,100.00
720109049 $                               1,600.00
470108423 $                               1,730.00
470104785 $                                  950.00
470109222 $                               3,800.00
720108958 $                               1,250.00
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi srk_powerbi ,

     

    Based on your description, you can create some measures as follows.

    count_today = CALCULATE(COUNT('Table 1'[AccountNum]),'Table 1'[RegisteredDate]=TODAY()-1)

    count_previous =

    var x1 = MAXX(FILTER(ALL('Table 1'),[RegisteredDate]<TODAY()-1&&WEEKDAY('Table 1'[RegisteredDate],2)<6),'Table 1'[RegisteredDate])

    return

    CALCULATE(COUNT('Table 1'[AccountNum]),'Table 1'[RegisteredDate]=x1)

    sum_today = CALCULATE(SUM('Table 2'[Amount]),'Table 1'[RegisteredDate]=TODAY()-1)

    sum_previous =

    var x1 = MAXX(FILTER(ALL('Table 1'),[RegisteredDate]<TODAY()-1&&WEEKDAY('Table 1'[RegisteredDate],2)<6),'Table 1'[RegisteredDate])

    return

    CALCULATE(SUM('Table 2'[Amount]),'Table 1'[RegisteredDate]=x1)


    Result:

     

    Hope that's what you were looking for.

    Best Regards,

    Yuna

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • srk_powerbi , Create a date Table with following columns

     

    Work Day = if(WEEKDAY([Date],2)>=6,0,1)
    Work Date = if(WEEKDAY([Date],2)>=6,BLANK(),[Date])
    Work Date Cont = if([Work Day]=0,maxx(FILTER('Date',[Date]<EARLIER([Date]) && [Work Day]<> EARLIER([Work Day]) ),[Date]),[Date])
    Work Date cont Rank = RANKX(ALL('Date'),[Work Date Cont],,ASC,Dense)

    Join it with Register Date

     


    This Day = CALCULATE(sum('Table'[Amount]), FILTER(ALL('Date'),'Date'[Work Date cont Rank]=max('Date'[Work Date cont Rank])))
    Last work day = CALCULATE(sum('Table'[Amount]), FILTER(ALL('Date'),'Date'[Work Date cont Rank]=max('Date'[Work Date cont Rank])-1))
    diff =[This Day] - [Last work day]

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    I assume that you have a calender table, try adding following column:

    PrevBusinessdAy = 
    	MAXX(
    		FILTER('Calendar';'Calendar'[Date] < EARLIER('Calendar'[Date])
    			&& WEEKDAY('Calendar'[Date];3) <5); 
    		'Calendar'[Date] 
            )

     Then create the measures.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi srk_powerbi ,

     

    Based on your description, you can create some measures as follows.

    count_today = CALCULATE(COUNT('Table 1'[AccountNum]),'Table 1'[RegisteredDate]=TODAY()-1)

    count_previous =

    var x1 = MAXX(FILTER(ALL('Table 1'),[RegisteredDate]<TODAY()-1&&WEEKDAY('Table 1'[RegisteredDate],2)<6),'Table 1'[RegisteredDate])

    return

    CALCULATE(COUNT('Table 1'[AccountNum]),'Table 1'[RegisteredDate]=x1)

    sum_today = CALCULATE(SUM('Table 2'[Amount]),'Table 1'[RegisteredDate]=TODAY()-1)

    sum_previous =

    var x1 = MAXX(FILTER(ALL('Table 1'),[RegisteredDate]<TODAY()-1&&WEEKDAY('Table 1'[RegisteredDate],2)<6),'Table 1'[RegisteredDate])

    return

    CALCULATE(SUM('Table 2'[Amount]),'Table 1'[RegisteredDate]=x1)


    Result:

     

    Hope that's what you were looking for.

    Best Regards,

    Yuna

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.