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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
RichOB
Post Partisan
Post Partisan

Table with every combination

Hi, using the table1, how do I get every combination like in table2 please?

 

Table1

SystemLocation
LaptopNewcastle
LaptopNewcastle
EmailNewcastle
ManchesterCRM
ManchesterCRM
ManchesterCRM


Table2

SystemLocationCount
LaptopNewcastle2
EmailNewcastle1
CRMNewcastle0
LaptopManchester0
EmailManchester0
CRMManchester3


Thanks

1 ACCEPTED SOLUTION
freginier
Super User
Super User

Hey there!

 

You can achieve the result in Power BI / DAX or SQL by generating every possible combination of System and Location, and then counting the occurrences.

 

Use the following DAX formula to create a new table in Power BI:

Table2 =
VAR Systems = VALUES(Table1[System])
VAR Locations = VALUES(Table1[Location])

RETURN
ADDCOLUMNS(
CROSSJOIN(Systems, Locations),
"Count", COUNTROWS(FILTER(Table1, Table1[System] = EARLIER([System]) && Table1[Location] = EARLIER([Location])))
)

What this does:

VALUES(Table1[System]) → Gets unique systems
VALUES(Table1[Location]) → Gets unique locations
CROSSJOIN() → Creates all possible combinations
COUNTROWS() → Counts occurrences of each pair

 

Hope this helps!

😁😁

View solution in original post

3 REPLIES 3
RichOB
Post Partisan
Post Partisan

Thanks for the solution and explanation!! 🙂

rajendraongole1
Super User
Super User

Hi @RichOB  - You can achieve this in Power BI using a cross join to get all possible combinations of System and Location, followed by a COUNTROWS measure to count occurrences. 

 

Table2 =
CROSSJOIN(
    DISTINCT( Tab1[System] ),
    DISTINCT( Tab1[Location] )
)
 

 

rajendraongole1_0-1740731404112.png

 

Count =
VAR sys = SELECTEDVALUE(Table2[System])
VAR loc = SELECTEDVALUE(Table2[Location])

VAR rowCount =
    CALCULATE(
        COUNTROWS(tab1),
        tab1[System] = sys,
        Tab1[Location] = loc
    )

RETURN
IF(ISBLANK(rowCount), 0, rowCount)
 
 
Please find the attached pbix file . hope thishelps.

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





freginier
Super User
Super User

Hey there!

 

You can achieve the result in Power BI / DAX or SQL by generating every possible combination of System and Location, and then counting the occurrences.

 

Use the following DAX formula to create a new table in Power BI:

Table2 =
VAR Systems = VALUES(Table1[System])
VAR Locations = VALUES(Table1[Location])

RETURN
ADDCOLUMNS(
CROSSJOIN(Systems, Locations),
"Count", COUNTROWS(FILTER(Table1, Table1[System] = EARLIER([System]) && Table1[Location] = EARLIER([Location])))
)

What this does:

VALUES(Table1[System]) → Gets unique systems
VALUES(Table1[Location]) → Gets unique locations
CROSSJOIN() → Creates all possible combinations
COUNTROWS() → Counts occurrences of each pair

 

Hope this helps!

😁😁

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.