Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

Data being excluded

Good monday to everyone!   I'm having trouble with some data. In my model, what I have is a table that contains sales from an SQL Server, a other table that contains more sales from an Excel archiv...
  • v-qiuyu-msft's avatar
    9 years ago

    Hi Anonymous,

     

    From your description, it seems data in table from Excel contains data from 01/01/15 to 10/01/16, while data in table from SQL Server contains data from 01/01/15 to 10/01/16. You merge those two tables use Merge Queries feature in desktop and you want to display YTD and YTD in last year same period, right?

     

    In your scenario, you can create a calendar table from the merged table:

     

    Date =
    CALENDAR (
        EOMONTH ( MIN ( 'Merge1'[Date] ), -1 ) + 1,
        EOMONTH ( MAX ('Merge1'[Date] ), 0 )
    )

     

    As the SQL table has the consecutive date column, you can build a relationship between the calendar table and merged table use this date column. Then create measures below:

     

    YTD for archive =
    IF (
        MIN ( 'Date'[Date] ) <= CALCULATE ( MAX ( 'Merge1'[Date] ), ALL ( 'Merge1' ) ),
        CALCULATE ( SUM ( 'Merge1'[Archive.Value] ), DATESYTD ( 'Date'[Date] ) )
    )

     

    YTD LY for archive =
        CALCULATE (
            [YTD for archive],
            SAMEPERIODLASTYEAR (VALUES ( 'Date'[Date] )
                    ))

     

    You can download attached .pbix to have a look.

     

    Reference:
    YTD last year DAX

     

    Best Regards,
    Qiuyun Yu

     

     

  • Anonymous's avatar
    Anonymous
    9 years ago

    Thanks v-qiuyu-msft for your reply.

     

    It helped me to work better with dates. I had created before a table with the dates for source, but not as calendar. About YTD and YTD LY, I had the idea of making them as part of the SUMMARIZED table columns and not as measures. Just as a personal decision.

     

    Anyway, thanks a lot for your help. It clarify a lot on how to work with dates.

     

    Have a great day!