Reply
avatar user
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

 

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 )
    )

@Anonymous

 

Please see the attached file as well

 

crtee.png

 

avatar user
Anonymous
Not applicable

Thank you very much  🙂

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)