Sum quarterly rows into annual results of revenue

조회 수: 1 (최근 30일)
Philip Chindamo
Philip Chindamo 2019년 2월 28일
답변: Akira Agata 2019년 3월 1일
Capture.PNG

답변 (1개)

Akira Agata
Akira Agata 2019년 3월 1일
How about the following?
% Create data table with same structure of yours
Date = repelem(datetime(2017,3,1)+3*calmonths(0:3),1,3)';
Code = repmat(categorical({'abc','def','ghi'}),1,4)';
Quantity = randi(100,12,1);
Price = randi(10,12,1)/10;
T = table(Date,Code,Quantity,Price);
% Calculate yearly revenue for each code
group = findgroups(T.Code);
Revenue =...
splitapply(@(x,y) sum(x.*y),T.Quantity,T.Price,group);

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by