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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
fredrikg
Helper I
Helper I

Dimension based on date

Hi,

I have this very simple model:

model1.png

 

 

 

 

 

 

 

 

 

 

 

Each project has a stage the project is in (StageId) and the date when the project reached that state (StageId_When).

The data comes straight from the database, so very easy.

Now, I want this:

model2.png

 

 

 

 

 

 

 

 

I have introduced a new dimension, StageExt. This is identical, except for projects with stage C (StageId = 3), yellow above:

  • If the stage was entered less than 6 months ago, then StageExt = "Stage C (< 6 months)"
  • If the stage was entered more than 6 months ago, then StageExt = "Stage C (>= 6 months)"

To do this, I need to:

  • Create the StageExt dimension table, and manually fill with values, partially from the Stage table.
  • Create a calculated column, StageExtId, with logic that assigns the value depending on the StageId and StageId_When values.

Although this is not a whole lot of work, it does get worse: I have 8 more dimensions to tackle in similar ways as Stage. Also, it is a little annoying, since this is something that is need on one single report only. All other reports will be based on the Stage dimension.

 

Is there a more clever way of doing this? It feels like something that perhaps can be solved in the report itself, and not in the model?

 

/Fredrik

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

Hi @fredrikg ,

 

Your "StageExt" column is based on "StageId" column and "StageId_When" column which are in the Project table. You could create a calculated column "StageExId"in the table "Peoject". It will generate data automaticly based on the following DAX.

StageExtId=
SWITCH (
    TRUE (),
    Project[StageID] = 3
        && DATEDIFF ( Project[StageID_when], TODAY (), MONTH ) <= 6, 3,
    Project[StageID] = 3
        && DATEDIFF ( Project[StageID_when], TODAY (), MONTH ) > 6, 4,
    Project[StageID]
)

Then you could create a new table based on this column.

StageExt =
DISTINCT(Project[StaheExtId])

Now you could create a new column in this new table to get Stage name with IF() or SWITCH() function.

The steps of creating tables and columns cannot be omitted, but at least you can automatically generate data without manually filling.

 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

1 REPLY 1
v-eachen-msft
Community Support
Community Support

Hi @fredrikg ,

 

Your "StageExt" column is based on "StageId" column and "StageId_When" column which are in the Project table. You could create a calculated column "StageExId"in the table "Peoject". It will generate data automaticly based on the following DAX.

StageExtId=
SWITCH (
    TRUE (),
    Project[StageID] = 3
        && DATEDIFF ( Project[StageID_when], TODAY (), MONTH ) <= 6, 3,
    Project[StageID] = 3
        && DATEDIFF ( Project[StageID_when], TODAY (), MONTH ) > 6, 4,
    Project[StageID]
)

Then you could create a new table based on this column.

StageExt =
DISTINCT(Project[StaheExtId])

Now you could create a new column in this new table to get Stage name with IF() or SWITCH() function.

The steps of creating tables and columns cannot be omitted, but at least you can automatically generate data without manually filling.

 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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