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

Help with relationships - customers & bookings

Hi Everyone

 

I am looking for some help to create a query. I suspect my problem is in the definition of the relationships but I can't see what I've done wrong.

 

Relationships

I have 2 tables, customers and bookings.

Both tables have a field "fullname"

I have defined a many-to-many relationship with customers filtering bookings.

PowerPi did not auto detect this relationship, I had to set it up manually.

 

additional fields relevant to query

The customers table has a whole number field called "total bookings"

The bookings table has a text field called "bookingtype" where the value can be 'term', 'taster' or 'special'

 

what I am trying to do

 

I am trying to count the number of customers who only made 1 booking and that booking was of type taster.

 

I tried to do this with a card visualisation as follows:

fields: count of customers.totalbookings

filter:

  • bookings.bookingtype = taster
  • customers.totalbookings = 1

 

but this doesn't work.

 

Can you help?

 

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

We can use the following formula to meet your requirement based on your sample data:

 

CountMeasure = 
COUNTX (
    FILTER ( 'Customers', [total bookings] = 1 ),
    VAR n = [fullname]
    RETURN
        IF (
            CALCULATE (
                COUNTROWS ( 'bookings' ),
                FILTER ( 'bookings', [fullname] = n && [Classtype] = "taster" )
            ) > 0,
            1,
            BLANK ()
        )
)

 

20.PNG

 


Best regards,

Community Support Team _ Dong Li
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

5 REPLIES 5
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can try to create a measure using following formula to meet your requirement:

 

CountMeasure =
COUNTX (
    FILTER ( 'Customers', [totalbookings] = 1 ),
    VAR name = [fullname]
    RETURN
        IF (
            CALCULATE (
                COUNTROWS ( 'bookings' ),
                FILTER ( 'bookings', [fullname] = name && [bookingtype] = "taster" )
            ) > 0,
            1,
            BLANK ()
        )
)


If it doesn't meet your requirement, kindly share your sample data and expected result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.

 


Best regards,

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

@Anonymous 

Can you please share the sample data and let us know the common column from the 2 tables to re-pro the issue from our end.

If possible please share the expected result.

Anonymous
Not applicable

Hello

 

I attached example data. I couldn't see how to upload the files so have copied in and few rows.

I have removed real names etc but hopefully this is sufficient to help you see my problem

With the data below I would expect the result of the query to be 4. customers 1,3,6 and 9 each have totalbookings = 1 and their bookings are of type taster.

 

customers table

Last nameFirst nameCreatedTotal bookingsCancellationsNo-showsfullname 
lastname1firstname119/09/2017101firstname1 lastname1
lastname2firstname206/07/2017000firstname2 lastname2
lastname3firstname309/04/2018100firstname3 lastname3
lastname4firstname404/06/2018200firstname4 lastname4
lastname5firstname506/10/2017300firstname5 lastname5
lastname6firstname615/11/2018100firstname6 lastname6
lastname7firstname712/11/2017400firstname7 lastname7
lastname8firstname823/11/2017201firstname8 lastname8
lastname9firstname918/06/2019100firstname9 lastname9
lastname10firstname1006/07/2017000firstname10 lastname10
lastname11firstname1106/07/2017000firstname11 lastname11
lastname12firstname1230/07/2017401firstname12 lastname12
lastname13firstname1306/01/2019300firstname13 lastname13
lastname14firstname1401/09/2017100firstname14 lastname14
lastname15firstname1504/08/2018200firstname15 lastname15
lastname16firstname1606/07/2017503firstname16 lastname16
lastname17firstname1724/06/2019100firstname17 lastname17
lastname18firstname1806/07/2017000firstname18 lastname18
lastname19firstname1912/09/2019400firstname19 lastname19

 

 

bookings table

 

Booking numberStartEndFirst name (customer)Last name (customer)ClassLocations for TastersVenues for BlocksProduct codePrivate eventStatusBooking statusfullnameclasstype
25480819286722427/8/2018 15:45########firstname1lastname1Big Builders Edinburgh (Ages 3 to 5)  Term 1 Broxburn Free Church32546K9YAU15FF8D1AA94FALSEnormalCustomer attendedfirstname1 lastname1taster
25480710270907127/8/2018 15:45########firstname2lastname2Big Builders Taster Classes Edinburgh (Ages 3 to 5)Stockbridge Lifecare Centre 325499NPL9160AD068F9DFALSEnormalCustomer attendedfirstname2 lastname2term
25480710688930027/8/2018 15:45########firstname3lastname3Big Builders Taster Classes Edinburgh (Ages 3 to 5)Stockbridge Lifecare Centre 325499NPL9160AD068F9DFALSEnormalCustomer attendedfirstname3 lastname3taster
25480731120438527/8/2018 15:45########firstname4lastname4Big Builders Edinburgh (Ages 3 to 5)  Term 1 Broxburn Free Church32546K9YAU15FF8D1AA94FALSEnormalCustomer attendedfirstname4 lastname4term
25480827835143927/8/2018 15:45########firstname5lastname5Big Builders Taster Classes Edinburgh (Ages 3 to 5)Stockbridge Lifecare Centre 325499NPL9160AD068F9DFALSEnormalCustomer attendedfirstname5 lastname5term
25480715399913827/8/2018 15:45########firstname6lastname6Big Builders Edinburgh (Ages 3 to 5)  Term 1 Broxburn Free Church32546K9YAU15FF8D1AA94FALSEnormalCustomer attendedfirstname6 lastname6taster
25480805254809827/8/2018 15:45########firstname7lastname7Big Builders Edinburgh (Ages 3 to 5)  Term 1 Broxburn Free Church32546K9YAU15FF8D1AA94FALSEnormalCustomer attendedfirstname7 lastname7term
25480827678870627/8/2018 16:00########firstname8lastname8Big Builders Taster Classes Fife (Ages 3 to 5)Dalgety Bay 3254RL7RHP162192BB5ACFALSEnormalCustomer attendedfirstname8 lastname8term
25480721577937827/8/2018 16:00########firstname9lastname9Big Builders Fife (Ages 3 to 5) Term 1 Juniper Green32547MXCTK16215684BCCFALSEnormalCustomer didn't turn upfirstname9 lastname9taster
25480721696496727/8/2018 16:00########firstname10lastname10Big Builders Fife (Ages 3 to 5) Term 1 Juniper Green32547MXCTK16215684BCCFALSEnormalCustomer didn't turn upfirstname10 lastname10term
25480803946158327/8/2018 16:00########firstname11lastname11Big Builders Fife (Ages 3 to 5) Term 1 Juniper Green32547MXCTK16215684BCCFALSEnormalCustomer didn't turn upfirstname11 lastname11term
25480713409789027/8/2018 16:00########firstname12lastname12Big Builders Fife (Ages 3 to 5) Term 1 Juniper Green32547MXCTK16215684BCCFALSEnormalCustomer attendedfirstname12 lastname12term
25480814729023727/8/2018 16:00########firstname13lastname13Big Builders Fife (Ages 3 to 5) Term 1 Juniper Green32547MXCTK16215684BCCFALSEnormalCustomer didn't turn upfirstname13 lastname13term
25480814729023727/8/2018 16:00########firstname14lastname14Big Builders Fife (Ages 3 to 5) Term 1 Juniper Green32547MXCTK16215684BCCFALSEnormalCustomer didn't turn upfirstname14 lastname14term
25480719213332327/8/2018 16:00########firstname15lastname15Big Builders Fife (Ages 3 to 5) Term 1 Juniper Green32547MXCTK16215684BCCFALSEnormalCustomer attendedfirstname15 lastname15term
25480826599276727/8/2018 16:45########firstname16lastname16Galileo Fife Term - 2 Dalgety Bay3254CFLPHT163F4A70AEEFALSEnormalCustomer told us they weren't comingfirstname16 lastname16term
25480813283900327/8/2018 16:45########firstname17lastname17Bricks Challenge Tasters Fife (Ages 6 to 😎  Dalgety Bay 3254CCR4AM164F5B1F8F7FALSEnormalCustomer attendedfirstname17 lastname17term
25480716748456327/8/2018 16:45########firstname18lastname18Bricks Challenge  - Edinburgh Term 1 Broxburn Free Church3254Y9WT7A163EA8445DCFALSEnormalCustomer attendedfirstname18 lastname18term
25480706127107727/8/2018 16:45########firstname19lastname19Bricks Challenge West Lothian Term 1  3254UK3HWP15FF8CE43EEFALSEcanceled firstname19 lastname19term

Thank you for your help.

 

 

Hi @Anonymous ,

 

We can use the following formula to meet your requirement based on your sample data:

 

CountMeasure = 
COUNTX (
    FILTER ( 'Customers', [total bookings] = 1 ),
    VAR n = [fullname]
    RETURN
        IF (
            CALCULATE (
                COUNTROWS ( 'bookings' ),
                FILTER ( 'bookings', [fullname] = n && [Classtype] = "taster" )
            ) > 0,
            1,
            BLANK ()
        )
)

 

20.PNG

 


Best regards,

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

That's great! Thank you for your help.

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.