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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
SoupyNoodles14
Frequent Visitor

Calculated Values in a Chart

Below is a table that I built in SQL using a cross join for each customer visit-priorService, where we provide an "as of" list of prior services done for each customer visit to a store. At visit 1, customer A has only one prior high-level service done on 1/1/2006. At visit 2, that same customer has two prior services done, S1 high and S2 medium. Finally, at visit 3, that same customer has four prior services done, S1, S2, S3, and S4. 

It is possible for a customer to have no prior services done, as indicated by customer D. This table is only part of a star-schema where my dashboard is centered on visits, so an entry in this table NEEDS to be recorded for each visit in the table below to identify that that visit for customer D is associated with 0 prior services. 

Each prior service has a severity and date (as well as other fields not listed in the table I have already created below). 

"Priors" Table:

 

CustomerVisitIDVisit DatePriorServiceIDPriorServiceDatePriorServiceSeverity
AV11/1/21S11/1/06High
AV26/1/21S11/1/06High
AV26/1/21S23/1/21Medium
AV38/1/21S11/1/06High
AV38/1/21S23/1/21Medium
AV38/1/21S37/15/21Low
AV38/1/21S47/17/21Medium
BV57/1/22S51/1/01High
BV57/1/22S61/10/01Medium
CV61/1/21S71/1/98Medium
CV61/1/21S86/1/05Low
CV79/1/21S71/1/98Medium
CV79/1/21S86/1/05Low
CV79/1/21S91/1/21High
DV810/1/21NULLNULLNULL

 

The dashboard I've created has slicers on visit date, prior service date, and prior service severity. 

 

I want to chart with the # of FILTERABLE prior services on the x-axis, and the number of visits on the y-axis. 

To achieve this, I initially built the following summary table separately in my data model.

Priors Counting Table = SUMMARIZE( 'Priors', Priors[VisitID], "PriorVisitCnt", DISTINCTCOUNTNOBLANK( 'Priors'[PriorServiceID] ) + 0 )

 

I linked this to my main visit-level table using the VisitID and got the chart I wanted, but the chart becomes meaningless when I filter on the service date or service type. Without any restrictions, there are upto 190 prior services done for a customer, but we need to see only the prior services done in 2017 when I filter on that service year for instance. It still shows 190 when I select 2017 on the slicer because there is a customer who had a grand total of 190 visits between 2000 (the oldest service recorded) and 2024 whose total amount of services keep showing. Based on my review of similar posts on this forum, it looks like measures can't be thrown into charts so easily but there COULD BE a workaround through calculated columns? I'm struggling a lot on this to even get the count of prior services per EACH visit on a measure to begin with. I already report on the min, max, median, and mean number of prior services done as of each visit for a customer, and it's very easy using a measure such as below. So I'm HOPEFUL something like this can be done at the chart-level?

 

Median = 

VAR Summary = SUMMARIZE('Priors', Priors[VisitID], "PriorVisitCnt", DISTINCTCOUNTNOBLANK( [PriorServiceID] ) + 0 )
RETURN MEDIANX ( Summary, [PowerBICnt] )

1 ACCEPTED SOLUTION

Unfortunately it did not, but thank you for trying. FYI, when I initially posted this, it was flagged as spam incorrectly and so I re-posted the question here: https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-Dynamic-Measure-of-Distinct-C.... The solution is working there. Someone at Microsoft un-flagged this original post. 

View solution in original post

5 REPLIES 5
v-kongfanf-msft
Community Support
Community Support

Hi @SoupyNoodles14 ,

 

Did you try the solution I provided, looking forward to your feedback.

 

Best regards,

Adamk Kong

Unfortunately it did not, but thank you for trying. FYI, when I initially posted this, it was flagged as spam incorrectly and so I re-posted the question here: https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-Dynamic-Measure-of-Distinct-C.... The solution is working there. Someone at Microsoft un-flagged this original post. 

v-kongfanf-msft
Community Support
Community Support

Hi @SoupyNoodles14 ,

 

Depend on your description,  maybe you can try formula like below to create measures:

Prior Service Count Per Visit = 
CALCULATE (
    DISTINCTCOUNT ( 'Priors'[PriorServiceID] ),
    ALLEXCEPT ( 'Priors', 'Priors'[VisitID] )
)
Prior Services Count = 
CALCULATE (
    DISTINCTCOUNT ( 'Priors'[PriorServiceID] ),
    FILTER(Priors,[Measure] = 0)
)
Visit Count = CALCULATE ( DISTINCTCOUNT ( 'Priors'[VisitID] ) )
Measure = IF(MAX(Priors[PriorServiceID]) = BLANK(),1,0)

vkongfanfmsft_0-1724744706167.png

Best Regards,
Adamk Kong

 

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

ahadkarimi
Solution Specialist
Solution Specialist

Hi @SoupyNoodles14, try two measures below, and if you encounter any issues, let me know.

 

Prior Service Count = 
VAR CurrentVisitID = SELECTEDVALUE('Priors'[VisitID])
RETURN
CALCULATE(
    COUNTROWS('Priors'),
    FILTER(
        'Priors',
        'Priors'[VisitID] = CurrentVisitID && 
        NOT(ISBLANK('Priors'[PriorServiceID])) -- Exclude blanks (NULLs)
    )
)
Visit Count = 
CALCULATE(
    COUNTROWS('Priors'),
    ALLEXCEPT('Priors', 'Priors'[VisitID]) -- Ensures grouping by VisitID
)

 

 

Did I answer your question?  If so, please mark my post as the solution!✔️
Your Kudos are much appreciated!  Proud to be a Responsive Resident!

Unfortunately @ahadkarimi what's happening with this is that PowerBI is not showing anything for the first measure you've suggested "Prior Service Count" and the second measure "Visit Count" is not returning a meaningful value. "Visit Count" is returning a number that is neither the total number of visits nor prior services and "Prior Service Count" is listing blank. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.