Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Help, Please, with DAX Date Processing

I’m honing my DAX skills in Power BI Desktop, and I’ve run into a snag that I hope the community can help me with.

 

I’ve been using Reza Rad’s excellent book, Power BI from Rookie to Rock Star: Book04 – “Power BI Modeling and DAX”.  In this exercise, we use the MS Adventure Works DB to determine the Total Sales to each customer and, using a slicer to select the most-recent “x” number of days, we then calculate the total sales dollars for each of those customers for that selected period.

 

I had no problem with getting the Total Sales per customer but, trying to get the Sales per Customer for the selected time period, PBI runs for 20+ minutes, then gives an error of “not enough memory” on my 8 GB PC, with essentially nothing else running.  As these tables are used for training, they are fairly small, so I'm sure I'm doing something wrong.

 

In the book the code to select the Sales for the selected time period is as follows:

Last Period Revenue = CALCULATE(

SUM(FactInternetSales[SalesAmount]),

DATESBETWEEN(

DimDate[FullDateAlternateKey],

DATEADD(LASTDATE(DimDate[FullDateAlternateKey]),-1*[Selected Period],DAY),

LASTDATE(DimDate[FullDateAlternateKey])

)

)

 

After the first failure, I copied the essential columns of the Adventure Works FactInternetSales table to a new table, using “SELECTCOLUMNS” but this didn’t work either.  (I do still have the original table in PBI, but I believe that shouldn’t impact the extract, as we’re now only working with the subset.)

 

I then tried simplifying the code, creating the following measures (Selected Period is the slicer's number of days for creating the range):

 

First Date In Range = (CALCULATE([Last Date In Range] -[Selected Period]))

 

Last Date In Range = LASTDATE('Subset of FactInternetSales21'[OrderDate])

 

With Selected Period = 60, I used cards to verify these two values: 6/1/2008 and 7/31/2008 are correct.

 

I tried another approach for the results columns, calculating it as:

Last Period Revenue = CALCULATE(SUM('Subset of FactInternetSales21'[SalesAmount]), DATESBETWEEN(DimDate5[FullDateAlternateKey], [First Date In Range], [Last Date In Range]))

 

This still locks up PBI.

 

Any suggestions would be most appreciated!!

  • Hi Anonymous , 

    I'm glad to cooperate you to solve the problem. If the answer is helpful, can you please accept it as a solution? Then we are able to close the thread. And more people who have the same request will benefit here.

     

    Best Regards,

    Xue Ding

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

10 Replies

  • v-xuding-msft's avatar
    v-xuding-msft
    Community Support

    Hi Anonymous ,

    For the problem of data loading slowly, you could reference the blog to analyze your report and improve the performance. 

    For incorrect results, I can't get you just based on description.  Please share a sample pbix file and your expected results. Then we will understand clearly. 

     

    Best Regards,

    Xue Ding

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

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks, Xue Ding, for trying to help!

       

      I'm not yet to the level of trying to fine-tune performance, but instead I think I'm probably doing something wrong in my DAX formulas.  I'm not sure that posting this response will allow me to upload the PBIX, but I'll try.  The expected results are the sum of total sales dollars for each customer for the selected period (which in my test is the latest 60 days of Order Dates).

       

      Thanks again!

      • Anonymous's avatar
        Anonymous
        Not applicable

        I hoped to get a link for uploading the PBIX when I clicked "Post", but obviously didn't . . .  Could you instruct me how to upload it, please?

         

        Thanks again for your help to this newbie!!