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
powerquest1234
Helper III
Helper III

Creating a table with SUMMARIZE() to get a correct count of cycle times

I have a table that shows information on Zoo ID #s, Specimen ID #s, and the current "stage" the specimen is in (ie for a frog, this would be egg, tadpole, or frog). 

My client wants the number of days between the beginning of the Tadpole stage and the end of the Frog stage.
- The data table has a row for each specimen's stage, showing it's start date and end date (ie there is a separate row for the Frog Egg stage, the Tadpole Stage, the Frog stage, but these are all the same animal--specimen ID #95).

- Each zoo has one specimen per species ever (so none of the zoos have a tadpole and a frog at the same time, or multiple frogs, or multiple tadpoles--it's always just one specimen per species. Once the frog dies or is given away, the zoo will never get another tadpole/frog/etc).
- You'll notice the Tadpole Start Date, Tadpole End Date, Frog Start Date, Frog End Date columns, Tadpole -> Frog (number of days) populate for every row in the Zoo ID, even on animals that don't have these stages. 
- The Tadpole -> Frog (number of days) is the number of days between the Tadpole Start Date and the Frog End Date. This is blank if there is NOT a Frog End Date.
- The rows will not always be in this same order

 

Zoo IDSpecimen IDStateSpecimen StageStage Start DateStage End DateTadpole Start DateTadpole End DateFrog Start DateFrog End DateTadpole Start Date to Frog End Date Cycle Time (number of days)
23WyomingFrog egg3/18/20174/1/20174/1/20175/1/20175/1/201710/21/2017203.00
23WyomingTadpole4/1/20175/1/20174/1/20175/1/20175/1/201710/21/2017203.00
23WyomingFrog5/1/201710/21/20174/1/20175/1/20175/1/201710/21/2017203.00
195TexasFrog egg1/10/20181/21/20181/21/20183/4/20183/4/201811/1/2018284.00
195TexasTadpole1/21/20183/4/20181/21/20183/4/20183/4/201811/1/2018284.00
195TexasFrog3/4/201811/1/20181/21/20183/4/20183/4/201811/1/2018284.00
12TexasButterfly egg3/1/20193/15/20191/21/20183/4/20183/4/201811/1/2018284.00
12TexasCaterpillar3/15/20193/19/20191/21/20183/4/20183/4/201811/1/2018284.00
12TexasCocoon3/19/20194/1/20191/21/20183/4/20183/4/201811/1/2018284.00
12TexasButterfly4/1/20194/15/20191/21/20183/4/20183/4/201811/1/2018284.00
46TexasTadpole10/5/20202/25/202010/5/20202/25/20202/25/20201/28/2021115.00
582IdahoFrog egg3/1/20204/5/20204/5/20208/9/20208/9/2020  
46TexasSnake egg4/29/20205/16/202010/5/20202/25/20202/25/20201/28/2021115.00
582IdahoTadpole4/5/20208/9/20204/5/20208/9/20208/9/2020  
46TexasFrog egg10/1/202010/5/202010/5/20202/25/20202/25/20201/28/2021115.00
35WyomingFrog egg10/5/202010/19/202010/19/2020    
46TexasFrog2/25/20201/28/202110/5/20202/25/20202/25/20201/28/2021115.00
149TexasParrot egg7/1/20218/1/20211/21/20183/4/20183/4/201811/1/2018284.00
510IdahoParrot egg4/21/20225/1/2022     
24WyomingMonkey7/1/2016 4/1/20175/1/20175/1/201710/21/2017203.00
35WyomingTadpole10/19/2020 10/19/2020    
46TexasSnake5/16/2020 10/5/20202/25/20202/25/20201/28/2021115.00
46TexasCoyote  10/5/20202/25/20202/25/20201/28/2021115.00
510IdahoParrot5/1/2022      
536IdahoGoat  4/5/20208/9/20208/9/2020  
149TexasParrot8/1/2021 1/21/20183/4/20183/4/201811/1/2018284.00
554IdahoSeal  4/5/20208/9/20208/9/2020  
582IdahoFrog8/9/2020 4/5/20208/9/20208/9/2020  


The issue I'm running into is that when I pull this dataset into Power BI and create a "Table" visual, I can't seem to get an accurate count of cycle times. For example, Zoo ID #1 only has one frog specimen and one cycle time. However, because the Tadpole Start Date, Tadpole End Date, Frog Start Date, Frog End Date and Tadpole to Frog Cycle Time columns populates on all nine rows for that zoo (even on the non-frog animals), this returns a count of 9 cycle times when it should really just count one cycle time for the only frog specimen. This is because every zoo in my hypothetical scenario will ever only have one frog.

I am thinking my next option is to use power query to create a cycle time column that only populates under particular conditions and pivot if necessary (so there's only one Tadpole to Frog cycle time per zoo). However, I find that I am over-relying on Power Query lately so I am curious if there is a way to get to an accurate cycle time count (one cycle time per zoo) with DAX. 

I tried adapting this code to my situation ( https://www.sqlbi.com/articles/understanding-data-lineage-in-dax/ ) but I'm not sure how I would filter out rows that are missing Frog End Dates (and thus no cycle time can be calculated) or filter only for zoos within a particular state. Is there a tutorial that someone would recommend?

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

Hi @powerquest1234 ,

You can create a measure as below to get the count of cycle times which include Tadpole to Frog Cycle Time, please find the details in the attachment.

Count of cycle times = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Specimen ID] ),
    FILTER (
        'Table',
        'Table'[Zoo ID] = SELECTEDVALUE ( 'Table'[Zoo ID] )
            && 'Table'[Specimen Stage] IN { "Tadpole", "Frog" }
    )
)

yingyinr_0-1650520108118.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

How to upload PBI in Community

Best Regards

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

View solution in original post

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @powerquest1234 ,

You can create a measure as below to get the count of cycle times which include Tadpole to Frog Cycle Time, please find the details in the attachment.

Count of cycle times = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Specimen ID] ),
    FILTER (
        'Table',
        'Table'[Zoo ID] = SELECTEDVALUE ( 'Table'[Zoo ID] )
            && 'Table'[Specimen Stage] IN { "Tadpole", "Frog" }
    )
)

yingyinr_0-1650520108118.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

How to upload PBI in Community

Best Regards

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

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.