cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Haripinnoju
Frequent Visitor

Dax query to create a calculated column date

Hi,

I have year and quarter columns, I need to create a calculated column from which I can get the date through this year and quarter columns, i.e., the date may be any either 1st of any month or in between the months.

Eg., Year 2022 quarter Q2 then date can be  04/05/2022 or 01/05/2022 etc.

 

I cannot use custom column.

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @Haripinnoju ,

 

Cannot use a calculated column to insert rows, the rows in the calculated column are the same as the rows in the table.

vcgaomsft_0-1686712838806.png

 

Consider creating a new table.

 

Table 2 = 
VAR _min_year =
    MIN ( 'Table'[Year] )
VAR _min_year_quarter =
    INT (
        RIGHT ( CALCULATE ( MIN ( 'Table'[Quarter] ), 'Table'[Year] = _min_year ), 1 )
    )
VAR _max_year =
    MIN ( 'Table'[Year] )
VAR _max_year_quarter =
    INT (
        RIGHT ( CALCULATE ( MIN ( 'Table'[Quarter] ), 'Table'[Year] = _min_year ), 1 )
    )
VAR _table =
    CALENDAR (
        DATE ( _min_year, 3 * _min_year_quarter - 2, 1 ),
        DATE ( _max_year, _max_year_quarter * 3, 1 )
    )
RETURN
    _table

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @Haripinnoju ,

 

Cannot use a calculated column to insert rows, the rows in the calculated column are the same as the rows in the table.

vcgaomsft_0-1686712838806.png

 

Consider creating a new table.

 

Table 2 = 
VAR _min_year =
    MIN ( 'Table'[Year] )
VAR _min_year_quarter =
    INT (
        RIGHT ( CALCULATE ( MIN ( 'Table'[Quarter] ), 'Table'[Year] = _min_year ), 1 )
    )
VAR _max_year =
    MIN ( 'Table'[Year] )
VAR _max_year_quarter =
    INT (
        RIGHT ( CALCULATE ( MIN ( 'Table'[Quarter] ), 'Table'[Year] = _min_year ), 1 )
    )
VAR _table =
    CALENDAR (
        DATE ( _min_year, 3 * _min_year_quarter - 2, 1 ),
        DATE ( _max_year, _max_year_quarter * 3, 1 )
    )
RETURN
    _table

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

some_bih
Super User
Super User

Hi @Haripinnoju it seems you need to create Date table in Power BI. Check link. I hope this help https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/ 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors