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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Different Statistics Based on Various Date Fields

Hi,

I have a Date table and Trans table. They are connected Trans[TransDate] ->Date[Date]. I can successfully create various measures to generate stats based on the TransDate, such as total transaction quantity, total time spent etc. However, I also have Trans[ProdOrderCreateDate] and Trans[ProdOrderFinishDate]. I'd like to calculate how many production orders have been created and finished based on these two fields. The production order id has duplicates in the Trans table as it's denormilized and contains many transactions per production order. Could I possibly utilize measures to calculate it or should I change my table structure?

Sample structure:

  • Date
    • [Date]
  • Trans
    • [ProdOrderId] (duplicate values)
    • [TransDate] (related to Date[Date])
    • [ProdOrderCreateDate]
    • [ProdOrderFinishDate]

Thank you

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

Hi @Anonymous,

 

I made one sample for your reference. You can refer to the following steps.

 

1. Create the relationship between tables like this.

2.PNG

 

2. Create the measures as below.

 

 

Createcount = CALCULATE(COUNTROWS(Trans),USERELATIONSHIP('Date'[Date],Trans[ProdOrderCreateDate]))
finishcount = CALCULATE(COUNTROWS(Trans),USERELATIONSHIP('Date'[Date],Trans[ProdOrderFinishDate]))
Transcount = CALCULATE(COUNTROWS(Trans))

 

 

 

Capture.PNG

 

For more details, please check the pbix as attached.

 

https://www.dropbox.com/s/sjmcwwceldlwv6v/Different%20Statistics%20Based%20on%20Various%20Date%20Fields.pbix?dl=0

 

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

3 REPLIES 3
v-frfei-msft
Community Support
Community Support

Hi @Anonymous,

 

I made one sample for your reference. You can refer to the following steps.

 

1. Create the relationship between tables like this.

2.PNG

 

2. Create the measures as below.

 

 

Createcount = CALCULATE(COUNTROWS(Trans),USERELATIONSHIP('Date'[Date],Trans[ProdOrderCreateDate]))
finishcount = CALCULATE(COUNTROWS(Trans),USERELATIONSHIP('Date'[Date],Trans[ProdOrderFinishDate]))
Transcount = CALCULATE(COUNTROWS(Trans))

 

 

 

Capture.PNG

 

For more details, please check the pbix as attached.

 

https://www.dropbox.com/s/sjmcwwceldlwv6v/Different%20Statistics%20Based%20on%20Various%20Date%20Fields.pbix?dl=0

 

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Hey @v-frfei-msft,

 

Thank you! That worked just fine, nice and easy. I did make a small tweak to your code to get it closer to my requirements. A quick test using a matrix and a visual work great.

 

Another question though, how can I create another table that will show only records from a selected cell that uses the new CreatedCount measure to display only relevant records. Below is a matrix screenshot based on the new measure. Usually, this kind of contectual filtering works fine with active relationships.

 

Also, can I create date filters (ex. CreatedDate filter) that use inactive relationship between the two tables?

 

 

CreatedCount = CALCULATE(DISTINCTCOUNT(Trans[ProdOrderId]),USERELATIONSHIP('Date'[Date],Trans[ProdOrderCreateDate]))

Pic.png

Greg_Deckler
Super User
Super User

I am assuming that you want statistics on these things over something like per month, per day, per year or something like that, yes?

 

If so, you want to check out these two measures in the Quick Measure Gallery:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365

 

You will need a disconnected date dimension.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.