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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Alex1
Frequent Visitor

Problem with data filtering

Hi all.

I have problem with data filtering.

My data:

Day customer first metDay customer returnNumber of customer
00100
0150
10100
1175
1250
20100
2180
2260
2320

I want to calculate share of returned customer. So i divide sum of customer by day to sum of customer on 0 day. But if there is no day for customer i dont need to calculate it. For example for customer first met at day 0 there is no day 2, so when i calculate share i want to divide 110 (50+60) on 200 (100+100), but pbi divide 110 (50+60) on 300 (100+100+100). So the result is:

 

Day customer returnShare correctShare in PBI
0100%100%
168%68%
255%37%
320%7%

 

Any suggestion would be great 🙂

1 ACCEPTED SOLUTION
Alex1
Frequent Visitor

Thx to all, two sleepless nights and i foundout how to do it. And, as always, it quet simple.

Retention share 2 =

divide(
sum(rep_ret[cou_user_ret]),
CALCULATE(
SUM(rep_ret[cou_user_ret]),
FILTER(
ALLSELECTED('rep_ret'[Cohort_day]),
'rep_ret'[Cohort_day]<=max('rep_ret'[Cohort_day])),rep_ret[Cohort lifetime]=0
)
)

 

Where
cou_user_ret - sum of customers
Cohort_day - day since first buy number
Cohort lifetime - activity day number 

View solution in original post

4 REPLIES 4
Alex1
Frequent Visitor

Thx to all, two sleepless nights and i foundout how to do it. And, as always, it quet simple.

Retention share 2 =

divide(
sum(rep_ret[cou_user_ret]),
CALCULATE(
SUM(rep_ret[cou_user_ret]),
FILTER(
ALLSELECTED('rep_ret'[Cohort_day]),
'rep_ret'[Cohort_day]<=max('rep_ret'[Cohort_day])),rep_ret[Cohort lifetime]=0
)
)

 

Where
cou_user_ret - sum of customers
Cohort_day - day since first buy number
Cohort lifetime - activity day number 

v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Alex1,

 

Could you please share your formula? How can I get 100% in day 0?

 

Best Regards!

Dale

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

No help?

MarcelBeug
Community Champion
Community Champion

It is rather complex for us to understand the logic. I have not the faintest idea how you got the mentioned Power BI results.

 

Below a suggestion in Power Query.

 

In query Sum, the numbers of customers are summed per "Day customer return".

In query SumDay0, a column with zeroes is added and the table is merged with itself, such that each "Day customer first met" is merged with its corresponding "Day customr return" record with value 0.

The result is grouped again to get the sums of "Number of customer"  on day 0 for each "Day customer return".

 

Finally both queries are merged and the sums are divided to get the share.

 

Query Sum:

 

let
    Source = Data,
    #"Grouped Rows" = Table.Group(Source, {"Day customer return"}, {{"Sum of customer", each List.Sum([Number of customer]), type number}})
in
    #"Grouped Rows"

 

Query SumDay0:

 

let
    Source = Data,
    #"Added Custom" = Table.AddColumn(Source, "Zero", each 0),
    #"Merged Queries" = Table.NestedJoin(#"Added Custom",{"Day customer first met", "Zero"},#"Added Custom",{"Day customer first met", "Day customer return"},"Day 0",JoinKind.LeftOuter),
    #"Expanded Day 0" = Table.ExpandTableColumn(#"Merged Queries", "Day 0", {"Number of customer"}, {"Day 0.Number of customer"}),
    #"Grouped Rows" = Table.Group(#"Expanded Day 0", {"Day customer return"}, {{"Sum of day 0 customers", each List.Sum([Day 0.Number of customer]), type number}})
in
    #"Grouped Rows"

 

Query Share:

 

let
    Source = Table.NestedJoin(Sum,{"Day customer return"},SumDay0,{"Day customer return"},"SumDay0",JoinKind.LeftOuter),
    #"Expanded SumDay0" = Table.ExpandTableColumn(Source, "SumDay0", {"Sum of day 0 customers"}, {"Sum of day 0 customers"}),
    AddedPercentage = Table.AddColumn(#"Expanded SumDay0", "Share", each [Sum of customer] / [Sum of day 0 customers], Percentage.Type)
in
    AddedPercentage

 

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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