Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Creating a date column

Hi there,

 

I have a data model with two fact tables (Fact_actual and Fact_budget) and a Date table (Dim_Date). The date table should "link" both fact tables. The Fact_actual table has a proper date column and granularity at day level while the budget table instead does not have any date column but just one "FY" column and a "Period" column and granularity at month level..

 

To make things harder my company has a fiscal year (FY) starting on Dec and ending on Nov. This means that Dec 2022 is Period 1 of FY23 and Jan 2023 is period 2 of FY23.

 

Could you please help me in creating with PowerQuery a proper date column in my Fact_budget table from existing FY and Period columns?

 

Many thanks in advance.

 

Regards,

C.

  • Hi, Anonymous 

    Thanks for your quick response!

    When the [Period]=1, the date is the Dec in the last year.Here are the steps you can refer to :

    We can click "Custom Column" and enter this:

    if [Period]=1 then #date([FY]+2000-1,12,1) else #date([FY]+2000,[Period]-1,1)
    
    

    Then we can modify the data type we want :

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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

6 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Idrissshatila,

       

      thanks for posting that nice video (I didn't know about thi Bravo tool), hower my request was different. I do already have my Date Table. What I miss is a date column in my Fact_budget table. Could you help me on that?

  • Hi , Anonymous 

    According to your description, you want to generate a date column in Power Query according to the other columns?
    First in Power Query , we can click "Custom Column" to add a column we need:

    Second, we can use IF() function to judge the other columns value and use the #date(2022,1,1) to generate a date value.

     

    For your company logic , i am not fully understand , if the above method can not meet your need , you may provide some sample data and then detailed explanation for your need and the end result  as a table to us .

    It will may be more clearly.

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Aniya, thanks for your support so far!!

       

      I have replicated what I want to obtain in Excel:

       

      I have calculate the rightmost table using the following excel formula:

       

      =DATE(IF([@Period]=1;[@FY]+2000-1;[@FY]+2000);IF([@Period]=1;12;[@Period]-1);1)

       

      I need to replicate exacly the same in powerpivot creating a new column. Unfortunately all attempts I did resolved eitheir in sintax or in data error. For example the following:

       

      = Table.AddColumn(#"Replaced Value", "Merged", each Text.Combine({"20", Text.From([FY], "it-IT"), Text.From([Period], "00"), "-01"}), type text)

       

      produce data "error" in all records.

       

      Many thanks,

      C.

       

       

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

        Hi, Anonymous 

        Thanks for your quick response!

        When the [Period]=1, the date is the Dec in the last year.Here are the steps you can refer to :

        We can click "Custom Column" and enter this:

        if [Period]=1 then #date([FY]+2000-1,12,1) else #date([FY]+2000,[Period]-1,1)
        
        

        Then we can modify the data type we want :

        Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

         

        Best Regards,

        Aniya Zhang

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