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
Anonymous
Not applicable

Variable Performance

Hi all, 

 

I have a calculated column and need to create two more columns based on same Variable. As we cannot re-use variables, which option is best in terms of performance/clearness of coding

 

Option 1. Create the two columns with same variable in each one

Option 2. Add a variable into the first calculated column, so I can use this in the new two columns -therefore, no need to rewrite the same variable 3 times 

Option 3. New ideas welcome! 

 

Example Option 1

Calculated column 1:  

Days_late = DATEDIFF('Table'[Due_date], TODAY(), Day)

 

Calculated column 2:

Late = VAR days_late = DATEDIFF('Table'[Due_date], TODAY(), Day)

RETURN
   SWITCH(TRUE(),
       days_late = 0, "Due today",

       AND(days_late>0, days_late < 15), "Late Less 15 days"

       days_late >=15, "Late More 15 days"

   "On Time"

    )

 

Calculated column 3:

On Time = VAR days_late = DATEDIFF('Table'[Due_date], TODAY(), Day)

RETURN
   SWITCH(TRUE(),
       AND(days_late<0, days_late >-15, "Due in Less 15 days",

       days_late<=-15, "due in More 15 days"

   "Late"

    )

 

Example Option 2

Calculated column 1:  

Days_late = VAR days_late = DATEDIFF('Table'[Due_date], TODAY(), Day)
RETURN
 days_late

 

Calculated column 2:

Late = VAR days_late = DATEDIFF('Table'[Due_date], TODAY(), Day)

RETURN
   SWITCH(TRUE(),
       days_late = 0, "Due today",

       AND(days_late>0, days_late < 15), "Late Less 15 days"

       days_late >=15, "Late More 15 days"

   "On Time"

    )

 

Calculated column 3:

On Time = VAR days_late = DATEDIFF('Table'[Due_date], TODAY(), Day)

RETURN
   SWITCH(TRUE(),
       AND(days_late<0, days_late >-15, "Due in Less 15 days",

       days_late<=-15, "due in More 15 days"

   "Late"

    )

 

Thank you for your time and support!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

When Calculated Days_late as the column, you can use the same in other columns

My suggestion would be this

Calculated column 1:  

Days_late = DATEDIFF('Table'[Due_date], TODAY(), Day)

Calculated column 2:


Late =
   SWITCH(TRUE(),
       [Days_late] = 0, "Due today",
       AND([Days_late]>0, [Days_late] < 15), "Late Less 15 days"
       [Days_late] >=15, "Late More 15 days"
   "On Time"
    ) 

Calculated column 3:
On Time =
   SWITCH(TRUE(),
       AND([Days_late]<0, [Days_late] >-15, "Due in Less 15 days",
       [Days_late]<=-15, "due in More 15 days"
   "Late"
    )

 

Is there a need for a third. Can they 2nd and 3rd can merge?

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

When Calculated Days_late as the column, you can use the same in other columns

My suggestion would be this

Calculated column 1:  

Days_late = DATEDIFF('Table'[Due_date], TODAY(), Day)

Calculated column 2:


Late =
   SWITCH(TRUE(),
       [Days_late] = 0, "Due today",
       AND([Days_late]>0, [Days_late] < 15), "Late Less 15 days"
       [Days_late] >=15, "Late More 15 days"
   "On Time"
    ) 

Calculated column 3:
On Time =
   SWITCH(TRUE(),
       AND([Days_late]<0, [Days_late] >-15, "Due in Less 15 days",
       [Days_late]<=-15, "due in More 15 days"
   "Late"
    )

 

Is there a need for a third. Can they 2nd and 3rd can merge?

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.