Forum Discussion

harshad_barge's avatar
6 years ago
Solved

Help with DAX code

Hi,

I have an excel output of a calculated DAX measure. The Calculated Pay (N) column is a sum of AUD Total Daily Earnings column, grouped by the Applicable Payroll Date. I want the Calculated Pay (Expected column to show the value only when the Applicable Payroll Date changes.
Many Thanks.

AUD Total Daily EarningsCalculatedPayCalculation DateApplicable Payroll DateCalculated Pay (N)Calculated Pay (Expected)
$327.81$2,031.341/09/2013 0:001/09/2013 0:002031.342031.34
$178.60$0.004/09/2013 0:0015/09/2013 0:001959.180
$185.73$0.005/09/2013 0:0015/09/2013 0:001959.180
$162.02$0.006/09/2013 0:0015/09/2013 0:001959.180
$228.94$0.007/09/2013 0:0015/09/2013 0:001959.180
$292.16$0.008/09/2013 0:0015/09/2013 0:001959.180
$151.95$0.0011/09/2013 0:0015/09/2013 0:001959.180
$151.96$0.0012/09/2013 0:0015/09/2013 0:001959.180
$151.96$0.0013/09/2013 0:0015/09/2013 0:001959.180
$189.94$0.0014/09/2013 0:0015/09/2013 0:001959.180
$265.92$1,959.1815/09/2013 0:0015/09/2013 0:001959.181959.18
$141.82$0.0018/09/2013 0:0029/09/2013 0:002063.780
$166.15$0.0019/09/2013 0:0029/09/2013 0:002063.780
$271.50$0.0020/09/2013 0:0029/09/2013 0:002063.780
$192.47$0.0021/09/2013 0:0029/09/2013 0:002063.780
$269.46$0.0022/09/2013 0:0029/09/2013 0:002063.780
$151.95$0.0025/09/2013 0:0029/09/2013 0:002063.780
$151.96$0.0026/09/2013 0:0029/09/2013 0:002063.780
$187.24$0.0027/09/2013 0:0029/09/2013 0:002063.780
$221.65$0.0028/09/2013 0:0029/09/2013 0:002063.780
$309.58$2,063.7829/09/2013 0:0029/09/2013 0:002063.782063.78
$151.96$0.0030/09/2013 0:0013/10/2013 0:002167.230
$171.93$0.001/10/2013 0:0013/10/2013 0:002167.230
$151.95$0.002/10/2013 0:0013/10/2013 0:002167.230
$289.32$0.005/10/2013 0:0013/10/2013 0:002167.230
$333.89$0.006/10/2013 0:0013/10/2013 0:002167.230
$405.20$0.007/10/2013 0:0013/10/2013 0:002167.230
$151.96$0.008/10/2013 0:0013/10/2013 0:002167.230
$141.82$0.009/10/2013 0:0013/10/2013 0:002167.230
$187.85$0.0010/10/2013 0:0013/10/2013 0:002167.230
$181.35$0.0011/10/2013 0:0013/10/2013 0:002167.232167.23
$169.19$0.0014/10/2013 0:0027/10/2013 0:002036.550
$184.08$0.0015/10/2013 0:0027/10/2013 0:002036.550
$173.75$0.0018/10/2013 0:0027/10/2013 0:002036.550
$247.18$0.0019/10/2013 0:0027/10/2013 0:002036.550
$285.67$0.0020/10/2013 0:0027/10/2013 0:002036.550
$151.96$0.0021/10/2013 0:0027/10/2013 0:002036.550
$151.96$0.0022/10/2013 0:0027/10/2013 0:002036.550
$151.96$0.0023/10/2013 0:0027/10/2013 0:002036.550
$254.88$0.0026/10/2013 0:0027/10/2013 0:002036.550
$265.92$2,036.5527/10/2013 0:0027/10/2013 0:002036.552036.55
$202.35$0.0030/10/2013 0:0010/11/2013 0:001928.30
$190.45$0.0031/10/2013 0:0010/11/2013 0:001928.30
  • Greg_Deckler's avatar
    Greg_Deckler
    6 years ago

    OK, the failure here was that your sample data was not representative of your actual data. In your actual data, we have to account for Employee_ID. So, that can be done like this:

     

    Result = 
        VAR __CalculatedPay = 'Sheet1'[Calculated Pay (N)]
        VAR __Next = 
            MINX(
                FILTER(
                    'Sheet1',
                    'Sheet1'[Calculation Date] > EARLIER('Sheet1'[Calculation Date]) &&
                        'Sheet1'[Employee_ID] = EARLIER('Sheet1'[Employee_ID])
                ),
                'Sheet1'[Calculation Date]
            )
        VAR __NextPay = 
            MINX(
                FILTER(
                    'Sheet1',
                    'Sheet1'[Calculation Date] = __Next &&
                        'Sheet1'[Employee_ID] = EARLIER('Sheet1'[Employee_ID])
                ),
                'Sheet1'[Calculated Pay (N)]
            )
    RETURN
        IF(__CalculatedPay <> __NextPay,__CalculatedPay,0)

     

    Updated PBIX is attached.

     

17 Replies

    • harshad_barge's avatar
      harshad_barge
      Helper I

      So the excel formula works but in excel. How do I translate this logic to DAX?

       

      =IF(AND(D2>=C2,E2<>E3),E2,0)

      AUD Total Daily EarningsCalculatedPayCalculation DateApplicable Payroll DateCalculated Pay (N)Calculated Pay (Expected)Expected (Excel Formula)
      $327.81$2,031.341/09/2013 0:001/09/2013 0:002031.342031.342031.34
      $178.60$0.004/09/2013 0:0015/09/2013 0:001959.1800
      $185.73$0.005/09/2013 0:0015/09/2013 0:001959.1800
      $162.02$0.006/09/2013 0:0015/09/2013 0:001959.1800
      $228.94$0.007/09/2013 0:0015/09/2013 0:001959.1800
      $292.16$0.008/09/2013 0:0015/09/2013 0:001959.1800
      $151.95$0.0011/09/2013 0:0015/09/2013 0:001959.1800
      $151.96$0.0012/09/2013 0:0015/09/2013 0:001959.1800
      $151.96$0.0013/09/2013 0:0015/09/2013 0:001959.1800
      $189.94$0.0014/09/2013 0:0015/09/2013 0:001959.1800
      $265.92$1,959.1815/09/2013 0:0015/09/2013 0:001959.181959.181959.18
      $141.82$0.0018/09/2013 0:0029/09/2013 0:002063.7800
      $166.15$0.0019/09/2013 0:0029/09/2013 0:002063.7800
      $271.50$0.0020/09/2013 0:0029/09/2013 0:002063.7800
      $192.47$0.0021/09/2013 0:0029/09/2013 0:002063.7800
      $269.46$0.0022/09/2013 0:0029/09/2013 0:002063.7800
      $151.95$0.0025/09/2013 0:0029/09/2013 0:002063.7800
      $151.96$0.0026/09/2013 0:0029/09/2013 0:002063.7800
      $187.24$0.0027/09/2013 0:0029/09/2013 0:002063.7800
      $221.65$0.0028/09/2013 0:0029/09/2013 0:002063.7800
      $309.58$2,063.7829/09/2013 0:0029/09/2013 0:002063.782063.782063.78
      $151.96$0.0030/09/2013 0:0013/10/2013 0:002167.2300
      $171.93$0.001/10/2013 0:0013/10/2013 0:002167.2300
      $151.95$0.002/10/2013 0:0013/10/2013 0:002167.2300
      $289.32$0.005/10/2013 0:0013/10/2013 0:002167.2300
      $333.89$0.006/10/2013 0:0013/10/2013 0:002167.2300
      $405.20$0.007/10/2013 0:0013/10/2013 0:002167.2300
      $151.96$0.008/10/2013 0:0013/10/2013 0:002167.2300
      $141.82$0.009/10/2013 0:0013/10/2013 0:002167.2300
      $187.85$0.0010/10/2013 0:0013/10/2013 0:002167.2300
      $181.35$0.0011/10/2013 0:0013/10/2013 0:002167.232167.232167.23
      $169.19$0.0014/10/2013 0:0027/10/2013 0:002036.5500
      $184.08$0.0015/10/2013 0:0027/10/2013 0:002036.5500
      $173.75$0.0018/10/2013 0:0027/10/2013 0:002036.5500
      $247.18$0.0019/10/2013 0:0027/10/2013 0:002036.5500
      $285.67$0.0020/10/2013 0:0027/10/2013 0:002036.5500
      $151.96$0.0021/10/2013 0:0027/10/2013 0:002036.5500
      $151.96$0.0022/10/2013 0:0027/10/2013 0:002036.5500
      $151.96$0.0023/10/2013 0:0027/10/2013 0:002036.5500
      $254.88$0.0026/10/2013 0:0027/10/2013 0:002036.5500
      $265.92$2,036.5527/10/2013 0:0027/10/2013 0:002036.552036.552036.55
      $202.35$0.0030/10/2013 0:0010/11/2013 0:001928.300
      $190.45$0.0031/10/2013 0:0010/11/2013 0:001928.31928.31928.3

       

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        Excel <> Power BI. Power BI cannot reference cells. But, pasting your Excel formula here might help. Power BI does not deal with cells, you have to filter your way to victory.

  • Anonymous's avatar
    Anonymous
    Not applicable
    I think your table is a table in the model, not a visual. So please use Power Query to do what you want. It's not only much much simpler but it IS THE WAY to do it.

    Best
    D