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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
SCNCKS1
Helper I
Helper I

Formatting to create a Gantt Chart

Hi, I am attempting to create a Gantt chart in powerbi. I have a production table that is filtered by a date table and a Project table (needed to have the project expenses filtered correctly for a different visual). The dax below works if I remove the selected value part of the measure, with the exception that it includes all production units even if there is no data in them. The issue appears to be the column that doesn't have a date, Any ideas on how i would filter those out?

 

my dax is:

 

CF Gantt =
VAR StartDate =
CALCULATE(
    Min(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    SELECTEDVALUE(PROD_COST_TABLE[ProductionUnit]),
    PROD_COST_TABLE[DA_Est_Qty_Complete] >0    )

VAR EndDate =
CALCULATE(
    MAX(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    SELECTEDVALUE(PROD_COST_TABLE[ProductionUnit]),
    PROD_COST_TABLE[DA_Est_Qty_Complete] >0    )
VAR ProjectPeriod =
MIN('Date'[WeekEnding]) >= StartDate
&& Max('Date'[WeekEnding]) <= EndDate

VAR RESULT =
If(
    ProjectPeriod,
    1)
RETURN
RESULT
 
SCNCKS1_0-1694205271476.png

 

SCNCKS1_2-1694205466988.png

 


 

1 ACCEPTED SOLUTION
SCNCKS1
Helper I
Helper I

I decided to add estimate and actual timelines. the code i used was:

 

Gantt =
VAR EST_StartDate =
CALCULATE(
    Min(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    PROD_COST_TABLE[DA_Est_Qty_Complete] >0
    )

VAR EST_EndDate =
CALCULATE(
    MAX(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    PROD_COST_TABLE[DA_Est_Qty_Complete] >0
    )
VAR EST_ProjectPeriod =
MIN('Date'[WeekEnding]) >= EST_StartDate
&& Max('Date'[WeekEnding]) <= EST_EndDate

VAR Actual_StartDate =
CALCULATE(
    Min(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    PROD_COST_TABLE[Qty_Complete] >0
    )
VAR Actual_EndDate =
CALCULATE(
    MAX(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    PROD_COST_TABLE[Qty_Complete] >0
    )
VAR Actual_ProjectPeriod =
MIN('Date'[WeekEnding]) >= Actual_StartDate
&& Max('Date'[WeekEnding]) <= Actual_EndDate

VAR EST_Actual_ProjectPeriod =
MIN('Date'[WeekEnding]) >= Actual_StartDate && MIN('Date'[WeekEnding]) >= Est_StartDate
&& Max('Date'[WeekEnding]) <= Actual_EndDate && Max('Date'[WeekEnding]) <= Est_EndDate

VAR RESULT =
SWITCH(
    TRUE(),
    EST_Actual_ProjectPeriod,3,
    Actual_ProjectPeriod,2,
    EST_ProjectPeriod,1
    )

RETURN
RESULT

View solution in original post

2 REPLIES 2
SCNCKS1
Helper I
Helper I

I decided to add estimate and actual timelines. the code i used was:

 

Gantt =
VAR EST_StartDate =
CALCULATE(
    Min(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    PROD_COST_TABLE[DA_Est_Qty_Complete] >0
    )

VAR EST_EndDate =
CALCULATE(
    MAX(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    PROD_COST_TABLE[DA_Est_Qty_Complete] >0
    )
VAR EST_ProjectPeriod =
MIN('Date'[WeekEnding]) >= EST_StartDate
&& Max('Date'[WeekEnding]) <= EST_EndDate

VAR Actual_StartDate =
CALCULATE(
    Min(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    PROD_COST_TABLE[Qty_Complete] >0
    )
VAR Actual_EndDate =
CALCULATE(
    MAX(PROD_COST_TABLE[Dates]),
    REMOVEFILTERS('Date'),
    PROD_COST_TABLE[Qty_Complete] >0
    )
VAR Actual_ProjectPeriod =
MIN('Date'[WeekEnding]) >= Actual_StartDate
&& Max('Date'[WeekEnding]) <= Actual_EndDate

VAR EST_Actual_ProjectPeriod =
MIN('Date'[WeekEnding]) >= Actual_StartDate && MIN('Date'[WeekEnding]) >= Est_StartDate
&& Max('Date'[WeekEnding]) <= Actual_EndDate && Max('Date'[WeekEnding]) <= Est_EndDate

VAR RESULT =
SWITCH(
    TRUE(),
    EST_Actual_ProjectPeriod,3,
    Actual_ProjectPeriod,2,
    EST_ProjectPeriod,1
    )

RETURN
RESULT
amitchandak
Super User
Super User

@SCNCKS1 , Refer if this can help

Matrix as Project plan Visual: https://youtu.be/R25QoiyoSVs

 

Power BI Matrix as Calendar Display & Conditional formatting: https://youtu.be/O93dTEt24ZE

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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