Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ogunlana Michael's avatar

How to get daily percentage of users for the past 7 days

$dailySignups = User::selectRaw('DATE(created_at) as date, COUNT(*) as count')
->groupBy('date')
->where('created_at', '>', Carbon::now()->subWeek())
 ->get();

It prints this as a response

	{
			"date": "2022-11-20",
			"count": 2									
	},
{
			"date": "2022-11-19",
			"count": 20								
	},
{
			"date": "2022-11-18",
			"count": 2									
	},

...

But I want to get  the daily percentage as swell something like this dummy response below, any help will be really appreciated

...
{
			"date": "2022-11-18",
			"count": 20,
            "percentage_change: 40	
					
}
...
0 likes
2 replies
tykus's avatar

What does the percentage change represent - change compared to what?

Please or to participate in this conversation.