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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Create a DAX calendar table and bring data in

I have a table that looks like this:

 

DateCountryResult
01-JanJapan1
01-JanGermany2
01-JanUSA1.4
03-JanGermany5
03-JanUSA2.3
07-JanUSA3
08-JanJapan2
08-JanGermany2
08-JanUSA7.1

 

I want to create a new table whose first column is a calendar. The second and third columns would show the data of the original table. It would look like this:

 

DateCountryResult
01-JanJapan1
01-JanGermany2
01-JanUSA1.4
02-JanJapan0
02-JanGermany0
02-JanUSA0
03-JanJapan0
03-JanGermany5
03-JanUSA2.3
04-JanJapan0
04-JanGermany0
04-JanUSA0
05-JanJapan0
05-JanGermany0
05-JanUSA0
06-JanJapan0
06-JanGermany0
06-JanUSA0
07-JanJapan0
07-JanGermany0
07-JanUSA3
08-JanJapan2
08-JanGermany2
08-JanUSA7.1

 

Does anyone know how to do this?

 

I created a calendar table with the following code

NewTable = CALENDAR ( min('Table'[Date]), max('Table'[Date]) )

I added the result with a column

ResultColumn = 
CALCULATE (
    SUM ( 'Table'[Result] ),
    FILTER ('Table', 'Table'[Date] = NewTable[Date] )
)

But how do I add the column with the countries in there?

 

1 ACCEPTED SOLUTION

@Anonymous

 

Please see the attached file as well

 

crtee.png

 


Regards
Zubair

Please try my custom visuals

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

You can create a CALCULATED TABLE transforming your Table into Desired Format.

 

Basically it Adds the missing dates and cross joins the dates with all the Countries that existed before that date

Assuming your TableName is Table1.

Go to Modelling Tab>>New Table

 

Calculated Table =
VAR AllDates =
    CALENDAR ( MIN ( Table1[Date] ), MAX ( Table1[Date] ) )
VAR MissingDates =
    EXCEPT ( AllDates, VALUES ( Table1[Date] ) )
VAR temp =
    UNION ( ADDCOLUMNS ( MissingDates, "Country", BLANK (), "Result", 0 ), Table1 )
VAR temp1 =
    GENERATE (
        SUMMARIZE ( temp, [Date] ),
        CALCULATETABLE (
            FILTER ( SUMMARIZE ( temp, [Country] ), [Country] <> BLANK () ),
            FILTER ( temp, [Date] <= EARLIER ( [Date] ) )
        )
    )
RETURN
    ADDCOLUMNS (
        temp1,
        "Result",
        VAR result =
            LOOKUPVALUE ( Table1[Result], Table1[Country], [Country], Table1[Date], [Date] )
        RETURN
            IF ( ISBLANK ( result ), 0, result )
    )

Regards
Zubair

Please try my custom visuals

@Anonymous

 

Please see the attached file as well

 

crtee.png

 


Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Thank you very much  🙂

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.