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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Jithin00
New Member

Dynamically adding columns

Hey all, i have got 4 quaters that is q1=oct,nov,dec     q2=Jan,feb,mar      q3=april,may,june     q4=july,aug,sept

(Note:- When the quater ends it should print the last 2 months data of the quater dynamically.)

So currently q1,q2,q3 is over so the table looks like this

 q1q2q3mayjune
Innovations55555
Loyalty44444
Value66666

 

But when quater 4 ends it should dynamically create columns q4, aug, sept and should look like

 q1q2q3q4augsept
Innovations555555
Loyaltly444444
Value666666

 

Requesting for help for the above problem.

 

Thankyou

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@lbendlin  @foodd  Thanks for your contribution on this thread.

Hi @Jithin00 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a calculated column as below in DateTable 

QtrOrMonth = 
VAR _today =
    TODAY ()
VAR _year =
    YEAR ( _today )
VAR _month =
    MONTH ( _today )
VAR _date = 'DateTable'[Date]
VAR _qtr =
    CALCULATE (
        MAX ( 'DateTable'[Quarter] ),
        FILTER ( 'DateTable', 'DateTable'[Date] = _today )
    )
VAR _qbdate =
    IF ( _qtr = "Q1", DATE ( _year, 10, 1 ), DATE ( _year - 1, 10, 1 ) )
VAR _qedate =
    SWITCH (
        _qtr,
        "Q2", DATE ( _year - 1, 12, 31 ),
        "Q3", DATE ( _year, 3, 31 ),
        "Q4", DATE ( _year, 6, 30 )
    )
VAR _month1 =
    EOMONTH ( _qedate, -2 ) + 1
RETURN
    IF (
        _date >= _qbdate
            && _date <= _qedate,
        IF ( _date >= _month1 && _date <= _qedate, [MonthName], [Quarter] )
    )

2. Create a sort order table

vyiruanmsft_1-1721702698734.png

3. Create the following measures

Sum of Innovations =
VAR _qmonth =
    SELECTEDVALUE ( 'Sort Order'[QtrMonth] )
VAR _qvalue1 =
    CALCULATE (
        SUM ( 'Table'[Innovations] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[QtrOrMonth] = _qmonth )
    )
VAR _qvalue2 =
    CALCULATE (
        SUM ( 'Table'[Innovations] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[Quarter] = _qmonth )
    )
RETURN
    IF (
        LEFT ( _qmonth, 1 ) = "Q",
        IF ( _qvalue1 < _qvalue2, _qvalue2, _qvalue1 ),
        SUM ( 'Table'[Innovations] )
    )
Sum of Loyalty = 
VAR _qmonth =
    SELECTEDVALUE ( 'Sort Order'[QtrMonth] )
VAR _qvalue1 =
    CALCULATE (
        SUM ( 'Table'[Loyalty] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[QtrOrMonth] = _qmonth )
    )
VAR _qvalue2 =
    CALCULATE (
        SUM ( 'Table'[Loyalty] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[Quarter] = _qmonth )
    )
RETURN
    IF (
        LEFT ( _qmonth, 1 ) = "Q",
        IF ( _qvalue1 < _qvalue2, _qvalue2, _qvalue1 ),
        SUM ( 'Table'[Loyalty] )
    )
Sum of Value =
VAR _qmonth =
    SELECTEDVALUE ( 'Sort Order'[QtrMonth] )
VAR _qvalue1 =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[QtrOrMonth] = _qmonth )
    )
VAR _qvalue2 =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[Quarter] = _qmonth )
    )
RETURN
    IF (
        LEFT ( _qmonth, 1 ) = "Q",
        IF ( _qvalue1 < _qvalue2, _qvalue2, _qvalue1 ),
        SUM ( 'Table'[Value] )
    )

4. Create a matrix visual(Columns: [QtryMonth] field of 'Sort Order' table  Values: the above 3 measures)

vyiruanmsft_0-1721702483418.png

Best Regards

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

@lbendlin  @foodd  Thanks for your contribution on this thread.

Hi @Jithin00 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a calculated column as below in DateTable 

QtrOrMonth = 
VAR _today =
    TODAY ()
VAR _year =
    YEAR ( _today )
VAR _month =
    MONTH ( _today )
VAR _date = 'DateTable'[Date]
VAR _qtr =
    CALCULATE (
        MAX ( 'DateTable'[Quarter] ),
        FILTER ( 'DateTable', 'DateTable'[Date] = _today )
    )
VAR _qbdate =
    IF ( _qtr = "Q1", DATE ( _year, 10, 1 ), DATE ( _year - 1, 10, 1 ) )
VAR _qedate =
    SWITCH (
        _qtr,
        "Q2", DATE ( _year - 1, 12, 31 ),
        "Q3", DATE ( _year, 3, 31 ),
        "Q4", DATE ( _year, 6, 30 )
    )
VAR _month1 =
    EOMONTH ( _qedate, -2 ) + 1
RETURN
    IF (
        _date >= _qbdate
            && _date <= _qedate,
        IF ( _date >= _month1 && _date <= _qedate, [MonthName], [Quarter] )
    )

2. Create a sort order table

vyiruanmsft_1-1721702698734.png

3. Create the following measures

Sum of Innovations =
VAR _qmonth =
    SELECTEDVALUE ( 'Sort Order'[QtrMonth] )
VAR _qvalue1 =
    CALCULATE (
        SUM ( 'Table'[Innovations] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[QtrOrMonth] = _qmonth )
    )
VAR _qvalue2 =
    CALCULATE (
        SUM ( 'Table'[Innovations] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[Quarter] = _qmonth )
    )
RETURN
    IF (
        LEFT ( _qmonth, 1 ) = "Q",
        IF ( _qvalue1 < _qvalue2, _qvalue2, _qvalue1 ),
        SUM ( 'Table'[Innovations] )
    )
Sum of Loyalty = 
VAR _qmonth =
    SELECTEDVALUE ( 'Sort Order'[QtrMonth] )
VAR _qvalue1 =
    CALCULATE (
        SUM ( 'Table'[Loyalty] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[QtrOrMonth] = _qmonth )
    )
VAR _qvalue2 =
    CALCULATE (
        SUM ( 'Table'[Loyalty] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[Quarter] = _qmonth )
    )
RETURN
    IF (
        LEFT ( _qmonth, 1 ) = "Q",
        IF ( _qvalue1 < _qvalue2, _qvalue2, _qvalue1 ),
        SUM ( 'Table'[Loyalty] )
    )
Sum of Value =
VAR _qmonth =
    SELECTEDVALUE ( 'Sort Order'[QtrMonth] )
VAR _qvalue1 =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[QtrOrMonth] = _qmonth )
    )
VAR _qvalue2 =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALLSELECTED ( 'DateTable' ), 'DateTable'[Quarter] = _qmonth )
    )
RETURN
    IF (
        LEFT ( _qmonth, 1 ) = "Q",
        IF ( _qvalue1 < _qvalue2, _qvalue2, _qvalue1 ),
        SUM ( 'Table'[Value] )
    )

4. Create a matrix visual(Columns: [QtryMonth] field of 'Sort Order' table  Values: the above 3 measures)

vyiruanmsft_0-1721702483418.png

Best Regards

lbendlin
Super User
Super User

I would recommend you use hierarchies instead.

foodd
Community Champion
Community Champion

Hello @Jithin00 , remember to adhere to the decorum of the Community Forum when asking a question.

Please provide your work-in-progress Power BI Desktop file (with sensitive information removed) that covers your issue or question completely in a usable format (not as a screenshot).

https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

This allows members of the Forum to assess the state of the model, report layer, relationships, and any DAX applied.

 

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.